I need to have HTML's input elements pattern ignore the case of the value,
like have if the regex is /[a-z]*/ could I get it to match all uppercase letters too?
(I know I could just do /[a-zA-Z]*/, but that was an example.)
The pattern attribute specifies a regular expression the form control's value should match. If a non- null value doesn't conform to the constraints set by the pattern value, the ValidityState object's read-only patternMismatch property will be true.
Note: The pattern attribute works with the following input types: text, date, search, url, tel, email, and password. Tip: Use the global title attribute to describe the pattern to help the user. Tip: Learn more about regular expressions in our JavaScript tutorial.
The default behavior of the regex is case sensitive which means upper and lowercase letters are interpreted as different.
I don't think it is possible.
The specification on <input pattern>
[1,2] specifies that
the pattern uses the ECMAScript (i.e. Javascript) flavor of regex
it is compiled "with the global, ignoreCase, and multiline flags disabled"
In Javascript, the only way to make a regex ignore case is to set the modifier externally (/.../i
). The PCRE syntax (?i)
is not supported.
Therefore, the pattern is always case-sensitive and [a-zA-Z]*
(i.e. making the regex itself explicitly case insensitive) is the only way to match the pattern in a case-insensitive way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With