Skip to content
Related Articles

Related Articles

HTML | pattern Attribute

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 24 Aug, 2022
View Discussion
Improve Article
Save Article

This attribute is used to specify the regular expression on which the input element value is checked. 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">

Element: This attribute is associated with <input> element only. 

Attribute: This attribute specifies the regular expression. 

Example: 

html




<!DOCTYPE html>
<html>
    <head>
        <title>pattern attribute</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>pattern attribute</h2>
        <form action="#">
            Password: <input type="text" name="Password"
            pattern="[A-Za-z]{3}" title="3 letter Password">
        <input type="submit">
        </form>
    </body>
</html>                   

Output:

  

Supported Browsers: The browser supported by pattern attribute are listed below:

  • Google Chrome 4.0 and above
  • Edge 12 and above
  • Firefox 4.0 and above
  • Opera 12.1 and above
  • Safari 5 and above
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!