Form Validation: Form validation is validating the values which are entered by the end-user during a form submission. For validating a form, Regular Expression plays a vital role. Let’s see what Regular Expression means.
Example 1: Form validation (validating an email)
This picture says a perfect email address is entered by the user, so the form is accepted and registration is done. When a person enters the wrong email the text box of the email is highlighted with red color border indicating it is an error.
Example 2: Form Validation (validating phone number )
Suppose assume the same registration form. Ever wonder why the number should be started with only from 6, 7, 8, 9 and not the remaining numbers. Here, also the picture is played by Regular Expression which helps in validating one’s correct mobile number. Restricting the users to enter only 10 digits where the first digit should of numbers “6,7,8,9” and rest all digits can be of any number from 0-9 is done purely by regular expressions “[^6-9][,0-9]” which help in validating the forms whether the information entered is relevant to the pattern specified.
This picture says a perfect phone number is entered by the user, so the form is accepted and registration is done. Upon entering the wrong phone number the text box of the phone number is highlighted with red color border indicating it is an error.