Input Search pattern Attribute

Definition and Usage

pattern Attribute sets or returns the value of the pattern attribute of the search field.

The HTML pattern attribute specifies a regular expression used to check the value of the search field.

Tip:Please use global HTML title Attribute or DOM title Use attributes to describe the pattern to help users.

See also:

JavaScript Tutorial:JavaScript Regular Expression

JavaScript Reference Manual:JavaScript RegExp Object

HTML Reference Manual:HTML <input> pattern Attribute

Example

Get the pattern attribute value of the search field:

var x = document.getElementById("mySearch").pattern;

Try it yourself

Syntax

Return the pattern attribute:

searchObject.pattern

Set the pattern attribute:

searchObject.pattern = regexp

Attribute value

Value Description
regexp Define the regular expression for checking the value of the text field.

Technical Details

Return Value: A string value representing a regular expression.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported 10.0 Supported Not Supported Supported