HTML5 > Forms Elements

Restrict patterns of characters in HTML5

How to restrict only pattern of character in textbox in HTML 5?


To restrict user to enter only specific pattern of characters in HTML 5, we use pattern attribute.

<input required pattern="[A-Za-z]{3}" title="3 alphabets characters only" />

In the above code snippet, we have pattern attribute  value set as [A-Za-z]{3} that forces the user to only enter three alphabets character (not more and not less). No numeric characters will be allowed.

The pattern attribute value is basically a regular expression, to learn more about regular expression, visit this post.

Output

 Views: 18044 | Post Order: 97



Write for us






Hosting Recommendations