Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML input pattern attribute

HTML pattern property

HTML input Tag Reference HTML tag

Example

An input field that can only contain three letters (no numbers or special characters):

Country code:

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 10, Firefox, Opera, and Chrome support the pattern attribute.

**Note:** Safari or Internet Explorer 9 and earlier versions do not support the the pattern attribute of the tag.


Definition and Usage

The pattern attribute specifies the regular expression used to validate the element's value.

**Note:** The pattern attribute applies to the following input types: text, search, url, tel, email, and password.

**Tip:** Please use the global title attribute to describe the pattern to help users.

**Tip:** You can learn more about Regular expressions knowledge.


Differences between HTML 4.01 and HTML5

The pattern attribute is new in HTML5.


Syntax

Attribute values

Value Description
regexp Specifies the regular expression used to validate the element's value.

HTML input Tag Reference HTML tag