Get the value of the pattern attribute of a search field:
var x = document.getElementById("mySearch").pattern;
Click the button to display the value of the pattern attribute of the search field.
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Search: <input type="search" id="mySearch" name="search" pattern="[^'\x22]+" title="Invalid input"> <input type="submit"> </form>//from w w w . j av a 2 s .co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("mySearch").pattern; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The pattern property sets or gets the value of the pattern attribute of a search field.
The pattern attribute sets a regular expression to validate the search field.
The pattern property accepts and returns a regular expression,