Input Text pattern Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

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

The pattern attribute sets a regular expression to check the text field's value.

Set the pattern property with the following Values

Value Description
regexp Sets a regular expression that the text field's value is checked against

Return Value

A String, representing a regular expression

The following code shows how to get the value of the pattern attribute of a text field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="#">
  Zip code: <input type="text" id="myText" name="zip_code">
  <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 v = document.getElementById("myText").pattern;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials