VOOZH about

URL: https://www.geeksforgeeks.org/html/html-pattern-attribute/

⇱ HTML pattern Attribute - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML pattern Attribute

Last Updated : 11 Jul, 2025

The HTML pattern attribute is used with <input> elements to specify a regular expression that the input's value must match for the form to be submitted. It enforces specific formatting rules, like requiring a certain number of characters or specific character types.

Syntax:

<input pattern = "regular_exp">

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

Attribute: This attribute specifies the regular expression. 

Example: In this example we use the pattern attribute to enforce a three-letter password. The input must match the specified pattern of three alphabetic characters, or it will not submit.

Output :

👁 Image

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

Comment
Article Tags: