What is the pattern attribute HTML?

Overview

In HTMLHypertext Markup Language, the pattern attribute is used to specify the regular expression on which we check the pattern of input values. This attribute works with the <input> elements.

We use this attribute with the following input types: text, email, date, password, etc.

Syntax


<input pattern = "regular_expression">

Parameters

This attribute takes regular_expression as its single argument.

Example

Explanation

In the above example, we set the pattern of password type to accept a minimum of 6 characters. So, if we add fewer characters, it shows a warning message.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources