regex mask that includes case insensitive flag is added to the mask
Closed this issue · 2 comments
When using a regex mask that includes the case insensitive flag /i
, the flag is getting applied as a mask character instead of being used by the regex. I am creating a regex for US states, but want to allow the user to enter upper or lower case.
Using the regex: /(?:AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY|NE)/i
the mask shows as /__/i
. How do I get the case sensitive flag to get used by the regex vs applied to the mask.
Thanks.
- https://jsfiddle.net/te019ymv/
- OS: Windows
- Browser: Chrome
- Inputmask version: 5.0.9
The regex
option is meant to be used with strings. If you want to allow users to input in any case, use the following setup:
$('#state').inputmask({
regex: '(?:AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY|NE)',
casing: 'upper'
});
Thank you. I misunderstood the casing
option to be where it applies it to the unmasked value after user entry, but not that it was used when applying the regex. But agree this works great. Thank you! I have updated the fiddle (https://jsfiddle.net/6qy09jow/) and works great: