1

Here's my original post: imask

I got that issue resolved but I'm wondering how to put multiple masks on an input. So for the phone input i want to put something like:

$('#phone').iMask({  
    type:'fixed',  
    mask:'(999) 999-9999 || 9 (999) 999-9999',  
    stripMask: false
});

But obviously that isn't working (or i wouldn't be posting). Anyone know how to do multiple conditions in a mask? Thanks

1
  • does iMask support multiple masks? The documentation doesn't mention it.
    – MrOBrian
    Sep 26, 2012 at 19:42

1 Answer 1

2

The value in mask is not a regular expression, it's a custom mask format.

The following should work

 $('#phone').iMask({  
    type:'fixed',  
    mask:'9 (999) 999-9999',  
    stripMask: false
 });

If the user doesn't want to enter the first digit, they can just skip over it by using the arrow to skip over that number

http://jsfiddle.net/GtQKh/23/

4
  • You should replace it's a custom mask format with it's a string representation
    – Ohgodwhy
    Sep 26, 2012 at 19:43
  • @Ohgodwhy Not sure why you think that is better. it's a string representation of what? of their own custom mask format. Sep 26, 2012 at 19:45
  • it's a string representation of regexp; you can check their code to see that regexp is exactly what they use.
    – Ohgodwhy
    Sep 26, 2012 at 19:47
  • @Ohgodwhy But you can't enter regular expressions in that string. It's not a string representation of a regular expression. It's their own custom format for specifying a mask, almost looks like regular expressions, but you can only use a,x,9 and everything else is treated literally. It's like the printf() function, the string formatting in there may end up creating regular expressions, but it's not a string representation of a regular expression Sep 26, 2012 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.