Javascript DOM HTML Input Email pattern Property get

Introduction

Get the value of the pattern attribute of an email field:

var x = document.getElementById("myEmail").pattern;

Click button to display the value of the pattern attribute for the email field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
  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  ava 2s . c  om

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

The pattern property sets or gets the value of the pattern attribute for an email field.

The pattern attribute stores a regular expression to validate the email field's value.

The pattern property accepts and returns a String type value.

The pattern property returns a String representing a regular expression.




PreviousNext

Related