An HTML form with an input field that can contain only three letters (no numbers or special characters):
More "Try it Yourself" examples below.
The pattern attribute specifies a regular expression that the <input> element's value is checked against.
Note: The pattern attribute works with the following input types: text, search, url, tel, email, and password.
Tip: Use the global title attribute to describe the pattern to help the user.
The numbers in the table specify the first browser version that fully supports the attribute.
The pattern attribute is new in HTML5.
|regexp||Specifies a regular expression that the <input> element's value is checked against|
An <input> element with type="password" that must contain 6 or more characters:
An <input> element with type="password" that must contain 8 or more characters that are of at least one number, and one uppercase and lowercase letter:
An <input> element with type="email" that must be in the following order: email@example.com (characters followed by an @ sign, followed by more characters, and then a "."
After the "." sign, you can only write 2 to 3 letters from a to z:
An <input> element with type="search" that CANNOT contain the following characters: ' or "
An <input> element with type="url" that must start with http:// or https:// followed by at least one character: