Inputmask icon indicating copy to clipboard operation
Inputmask copied to clipboard

Switch Mask on typing

Open andreknieriem opened this issue 2 years ago • 1 comments

Hi there. I need a field where you can put an accountnumer or an iban. I need to switch the masks on user is typing. If the mask starts with a letter instead of a number I need the iban mask, else the number mask.

Tried something like this, but this didn't work

$('.js-bankField.iban').on('keydown', function(){
    let val = $(this).val();
    let firstSigns = val.substring(0, 1);
    let mask = (parseInt(firstSigns)==firstSigns) ? '**9999999999999999999999999999999999999999' : '**99 9999 9999 9999 9999 99'
    Inputmask({'mask': mask}).mask($(this))
});

andreknieriem avatar Jul 14 '22 12:07 andreknieriem

I think you could use the solution from https://github.com/RobinHerbots/Inputmask/issues/2109#issuecomment-492563071 and add the account mask to the validMasks.

kleinph avatar Sep 14 '22 15:09 kleinph

@andreknieriem ,

Try something like this

    Inputmask([ '9{10,40}' , 'aa99 9999 9999 9999 9999 99'],{
        casing: "upper"
    }).mask("test1");

RobinHerbots avatar Sep 30 '22 13:09 RobinHerbots