Input Email pattern Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Email field

Description

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

Return Value

A String, representing a regular expression

The following code shows how to get the value of the pattern attribute of an email field:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials