HTML 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}"><br>
<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.
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.
Standard Syntax
<element pattern="regexp">
Browser Support
Status
Applies to:
The pattern attribute can be used on the following element:
Attribute Values
Value | Description |
---|---|
regexp | Specifies a regular expression the value must match to be valid. |