The pattern
attribute on an <input> tag specifies a regular expression which validates the input data before form submission.
The validation takes places just before the form is submitted.
A pattern
attribute on an <input> element.
The textbox requires a 3 letter country code before submission.
<form action="/tutorial/action.html">
Country code
<input type="text" name="countrycode"
pattern="[A-Za-z]{3}" required
placeholder="3 letter code"><br /><br />
<input type="submit">
</form>
The pattern
attribute specifies a regular expression for input validation.
The regular expression validates the user input before submission.
This attribute works with these input types:
<input pattern="regexp">
Value | Description |
---|---|
regexp | A regular expression. |
Here is when pattern
support started for each browser:
Chrome
|
5.0 | May 2010 |
Firefox
|
4.0 | Mar 2011 |
IE/Edge
|
10.0 | Sep 2012 |
Opera
|
9.6 | Oct 2008 |
Safari
|
10.1 | Mar 2017 |
Back to <input>