THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Input URL pattern Property

Input URL Object Reference Input URL Object

Example

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

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

The result of x will be:

https?://.+
Try it Yourself »

Definition and Usage

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

The pattern attribute specifies a regular expression that the URL 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

Internet Explorer Firefox Opera Google Chrome Safari

The pattern property is supported in Internet Explorer 10, Firefox, Opera, and Chrome.

Note: The pattern property is not supported in Internet Explorer 9 and earlier versions, or in Safari.


Syntax

Return the pattern property:

urlObject.pattern

Set the pattern property:

urlObject.pattern=regexp

Property Values

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

Technical Details

Return Value: A String, representing a regular expression

More Examples

Example

Set the pattern of a URL field to only accept URL's that start with http(s)://www.facebook.com/:

document.getElementById("myURL").pattern = "http://www\.facebook\.com\/(.+)|https://www\.facebook\.com\/(.+)";
Try it Yourself »

Related Pages

HTML reference: HTML <input> pattern Attribute


Input URL Object Reference Input URL Object