HTML <input> pattern Attribute

The pattern attribute on an <input> tag specifies a regular expression which validates the input data before form submission.

Example

#

A pattern attribute on an <input> element.
The textbox requires a 3 letter country code before submission.

Country code  

<form action="/tutorial/action.html">
  Country code &nbsp; 
  <input type="text" name="countrycode" 
         pattern="[A-Za-z]{3}" required
         placeholder="3 letter code"><br /><br />

  <input type="submit">
</form>

Using pattern

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:


Syntax

<input pattern="regexp">

Values

#

Value Description
regexp A regular expression.

Browser support

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

You may also like

 Back to <input>
Guides