Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <input> pattern Attribute

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

The validation takes places just before the form is submitted.

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>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides