Input URL pattern Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input URL

Description

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

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

Set the pattern property with the following Values

Value Description
regexp Sets a regular expression that the URL 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 URL field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="#">
  Facebook profile: <input type="url" id="myURL" name="fb">
  <input type="submit">
</form>// w w w .  j av a 2  s .  c  om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myURL").pattern ="http://www\.facebook\.com\/(.+)|https://www\.facebook\.com\/(.+)";
    document.getElementById("myURL").title ="URL must start with http://www.facebook.com/";

    document.getElementById("demo").innerHTML ="sets";
}
</script>

</body>
</html>

Related Tutorials