Open In App
Related Articles

HTML | pattern Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

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="#">
        <label for="userPass">Password:</label>
        <input type="text" name="password" id="userPass" pattern="[A-Za-z]{3}" title="3 letter Password">
        <input type="submit" value="submit">
    </form>
</body>
 
</html>


Output1:

 

  

Output2:  (When entering a password of more than 3 characters)

 

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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Dec, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials