Does html5 pattern attribute work in every browser or not? If doesn't work which technique should I use to work in every browser?
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.
Overview. In HTML, the pattern attribute is used to specify the regular expression on which we check the pattern of input values. This attribute works with the <input> elements. We use this attribute with the following input types: text, email, date, password, etc.
After a bit of trial and error, turns out you can use pattern="^[\p{L}]${1,25} to allow ASCII letters and Unicode variants, accented letters and special characters.
No, it doesn't. Though you can use JavaScript to get the attribute and validate it that way.
if ( ! input.hasOwnProperty('pattern')
&& ~input.value.search(input.pattern)) {
// Valid input field for browsers which don't support `pattern` attribute.
}
jsFiddle.
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