
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input URL pattern Property
The HTML DOM Input URL pattern property sets/returns the regular expression corresponding to URL Input. The pattern attribute’s value is checked against the text typed in url field.
Sytax
Following is the syntax −
- Returning regular expression
inputURLObject.pattern
- Setting pattern to regular expression
inputURLObject.pattern = ‘RegExp’
Example
Let us see an example of Input URL pattern property −
<!DOCTYPE html> <html> <head> <title>Input URL pattern</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="submit"] { border-radius: 10px; } </style> </head> <body> <form onsubmit="checkPattern()"> <fieldset> <legend>URL-pattern</legend> <label for="URLSelect">URL : <input type="url" id="URLSelect" pattern="https?://www.+[a-zA-Z0-9]+.com"> </label> <input type="submit" value="Submit"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputURL = document.getElementById("URLSelect"); divDisplay.textContent = 'pattern: '+inputURL.pattern; function checkPattern() { if(inputURL.value !== ''){ alert("Redirecting to "+User); } } </script> </body> </html>
Output
This will produce the following output −
Before clicking ‘Submit’ button −
After clicking ‘Submit’ button with invalid pattern −
After clicking ‘Submit’ button with valid pattern −
- Related Articles
- HTML DOM Input URL autocomplete Property
- HTML DOM Input URL autofocus Property
- HTML DOM Input URL defaultValue Property
- HTML DOM Input URL disabled Property
- HTML DOM Input URL form Property
- HTML DOM Input URL maxLength Property
- HTML DOM Input URL name Property
- HTML DOM Input URL placeholder Property
- HTML DOM Input URL readOnly Property
- HTML DOM Input URL required Property
- HTML DOM Input URL size Property
- HTML DOM Input URL type Property
- HTML DOM Input URL value Property
- HTML DOM Input Password pattern property
- HTML DOM Input Email pattern Property

Advertisements