Input Text pattern Property

❮ Input Text Object

Example

Get the value of the pattern attribute of a text field:

var x = document.getElementById("myText").pattern;
Try it Yourself »

Description

The pattern property sets or returns the value of the pattern attribute of a text field.

The pattern attribute specifies a regular expression that the text field's value is checked against.

Tip: Use the global HTML title attribute or the DOM title property to describe the pattern to help the user.

Tip: Learn more about Regular Expressions in our JavaScript Tutorial.

Tip: Also see our Complete JavaScript RegExp Reference.


Browser Support

Property
pattern Yes 10.0 Yes Not supported Yes


Syntax

Return the pattern property:

textObject.pattern

Set the pattern property:

textObject.pattern = regexp

Property Values

Value Description
regexp Specifies a regular expression that the text field's value is checked against

Technical Details

Return Value: A String, representing a regular expression

More Examples

Example

Set the pattern of a text field to only contain numbers from 1 to 3:

document.getElementById("myText").pattern = "[1-3]";
Try it Yourself »

Related Pages

HTML reference: HTML <input> pattern attribute


❮ Input Text Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.