RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

Switch Mask on typing #2634

Closed andreknieriem closed 1 year ago

andreknieriem commented 2 years ago

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))
});
kleinph commented 2 years ago

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.

RobinHerbots commented 1 year ago

@andreknieriem ,

Try something like this

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