Advertisement
Home Open Editor ❯

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>

Try this code ❯

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">


Applies to:

The pattern attribute can be used on the following element:

Element Attribute
<input> pattern

Advertisement

Attribute Values

Value Description
regexp Specifies a regular expression the value must match to be valid.
Home Open Editor ❯
Advertisement