HTML <input> pattern Attribute
Example
<form action="action.php">
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{5}">
<input type="submit" value="Submit">
</form>
Meaning
The pattern attribute specifies a regular expression against which the field should be validated.
The title attribute should be provided when this attribute is used, to give an indication of what is an acceptable pattern and what is not acceptable.
Standard Syntax
HTML: <input pattern="regexp">
XHTML: <input pattern="regexp"/>
Browser Support
Note:
- Partial support refers to not displaying a message for invalid patterns.
- Safari browsers support the pattern attribute but will still allow forms to be submitted if the pattern is incorrect.
Status
Advertisement
Attribute Values
| Value | Description |
|---|---|
| regexp | Specifies a regular expression the value must match to be valid. |