Javascript examples for DOM HTML Element:Input Email field
The pattern property sets or gets the pattern attribute of an email field, which is used to check the email field's value.
Set the pattern property with the following Values
Value | Description |
---|---|
regexp | Sets a regular expression to check the email field's value |
A String, representing a regular expression
The following code shows how to get the value of the pattern attribute of an email field:
<!DOCTYPE html> <html> <body> <form action="#"> E-mail: <input type="email" id="myEmail" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"> <input type="submit"> </form>//from w ww .j a va 2s . co m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myEmail").pattern; document.getElementById("demo").innerHTML = x; } </script> </body> </html>