Javascript examples for DOM HTML Element:Input Text
The pattern property sets or gets the value of the pattern attribute of a text field.
The pattern attribute sets a regular expression to check the text field's value.
Set the pattern property with the following Values
Value | Description |
---|---|
regexp | Sets a regular expression that the text field's value is checked against |
A String, representing a regular expression
The following code shows how to get the value of the pattern attribute of a text field:
<!DOCTYPE html> <html> <body> <form action="#"> Zip code: <input type="text" id="myText" name="zip_code"> <input type="submit"> </form>/* w w w. j a v a 2s. c o m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var v = document.getElementById("myText").pattern; document.getElementById("demo").innerHTML = v; } </script> </body> </html>