Javascript DOM HTML Input Password pattern Property get

Introduction

Get the value of the pattern attribute of a password field:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p>A form with a password field that must contain 6 or more characters:</p>

<form action="/action_page.php">
  Password: <input type="password" id="myPsw" name="pw" pattern=".{6,}" title="Six or more characters">
  <input type="submit">
</form>//  ww w .j a va  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>

The pattern property sets or gets the value of the pattern attribute of a password field.

The pattern attribute sets a regular expression to validate the password field's value.

The pattern property accepts and returns a regular expression,




PreviousNext

Related