Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex mask that includes case insensitive flag is added to the mask #2824

Open
rmunson8 opened this issue Oct 18, 2024 · 2 comments
Open

regex mask that includes case insensitive flag is added to the mask #2824

rmunson8 opened this issue Oct 18, 2024 · 2 comments

Comments

@rmunson8
Copy link

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.

@Techn1c4l
Copy link

Techn1c4l commented Oct 21, 2024

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'
});

@rmunson8
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants