HTML & CSS, WEB

Regular Expressions in HTML

In HTML5 there is a new input field attribute called pattern.

This attribute specifies a regular expression that the <input> element’s value is checked against.

The pattern attribute is available for text, search, url, tel, email, and password field.

If you would like to describe the pattern, to help the user fill the field correctly use the title attribute.

This feature works in Firefox, Opera and Chrome.

Example:

Provide a 3 digit number:

1
<input pattern="[0-9]{3,3}">

Username (at least 8 characters):

1
<input pattern="[a-zA-Z]{8,}">