Javascript examples for DOM HTML Element:Input Password
The pattern property sets or gets the pattern attribute of a password field, which sets a regular expression that the password field's value is checked against.
Set the pattern property with the following Values
Value | Description |
---|---|
regexp | Sets a regular expression that the password 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 password field:
<!DOCTYPE html> <html> <body> <form action="#"> Password: <input type="password" id="myPsw" name="pw" pattern=".{6,}" title="Six or more characters"> <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 x = document.getElementById("myPsw").pattern; document.getElementById("demo").innerHTML = x; } </script> </body> </html>