

Any time you can use a specific feature of HTML, instead of resorting to building regular expressions, you should use it. Or anything else you could with something elseĮmail addresses and dates are common enough that specific form input types already exist for them, so there is no need to use pattern. Instead of all that, just use the date input. On top of all that, you have to parse the string into a usable date object once you get it on the server. Also, there is nothing to stop invalid dates like February 31, or dates too far in the future like. People like to format dates different (MM/DD/YY, DD MONTHNAME YYYY, etc.), and they probably won’t read your instructions on proper formatting the first few times they try it.

For example + is a pattern that matches against a string of any length, as long as the string contains only lowercase letters ( a-z), uppercase letters ( A-Z), or numerals ( 0-9).Įxample Patterns Username Patterns Only letters (either case), numbers, and the underscore no more than 15 characters. A regular expression is a formalized string of characters that define a pattern. It works by matching the input value against a regular expression. The pattern attribute of the element allows you to add basic data validation without resorting to JavaScript.
