Input URL pattern attribute

Definition and Usage

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

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

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

See also:

JavaScript Tutorial:Regular Expressions

JavaScript Reference Manual:RegExp Object

HTML Reference Manual:HTML <input> pattern Attribute

Example

Example 1

Get the value of the pattern property of the URL field:

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

Try it yourself

Example 2

Set the URL field pattern to only accept URLs that start with http(s)://www.w3vip.cn/:

document.getElementById("myURL").pattern = "http://www\.w3vip\.cn\/(.+)|https://www\.w3vip\.cn\/(.+)";

Try it yourself

Syntax

Return the pattern property:

urlObject.pattern

Set the pattern property:

urlObject.pattern = regexp

Attribute Value

Value Description
regexp Specifies the regular expression to check the URL field value.

Technical Details

Return value: A string value representing the regular expression.

Browser Support

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