HTML pattern Attribute

❮ HTML Attributes

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:




Standard Syntax

<element pattern="regexp">



Browser Support




Status




Applies to:

The pattern attribute can be used on the following element:

Element Attribute
<input> pattern






Attribute Values

Value Description
regexp Specifies a regular expression the value must match to be valid.
❮ HTML Attributes