How to set a regular expression for an input element value that checked against using HTML ?
In this article, we will use <input> pattern attribute to set the regular expression pattern for an input field that checked against. The HTML <input> pattern attribute is used to specify the regular expression on which the input elements value is checked against. This attribute works with the following input types: text, password, date, search, email, etc. Use the Global title attribute to describe the pattern for helping the user.
Syntax:
<input pattern = "regular_exp">
Attribute Value: The pattern attribute is used to set the pattern of regular expression that enters into the input field.
Example: This example illustrates the use of pattern attribute in <input> element.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
How to specify a regular expression
that an input element's value
is checked against?
</ title >
</ head >
< body style = "text-align: center;" >
< h1 style = "color: green;" >
GeeksforGeeks
</ h1 >
< h3 >
How to specify a regular expression
that an input < br >element's value
is checked against?
</ h3 >
< form action = "#" >
Name: < input type = "text" name = "Password"
pattern = "[A-Za-z]{10}"
title = "Three letter Password" >
< input type = "submit" >
</ form >
</ body >
</ html >
|
Output:
Supported Browsers: The browser supported by HTML <input> pattern attribute are listed below:
- Google Chrome 5.0
- Internet Explorer 10.0
- Firefox 4.0
- Safari 10.1
- Opera 9.6
Last Updated :
25 Dec, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...