HTML5: Regular Expression

Tech Tricks

The biggest advantage to field validation is the addition of pattern attribute to most of the form fields where validation applies. The pattern attribute specifies a regular expression that the element’s value is checked against. This attribute responsible for checking or matching the pattern, specified for the input field and considered to be invalid if user enters the wrong pattern. Upon invalid input, it will display an error message as a tooltip or in the statusbar.

So, let’s go through an example of showing how it works.

The above example validate the username for minimum 5 characters and maximum 20 characters and will accept only alpha-bates (both upper and lower case).

Check the below output on invalid input. It will pop-up the error message as “Please match the requested format.”


But, how can we customize the error message?? ❓ 😐

💡 😎 It’s too simple though :). We can…

View original post 138 more words