Data validation is where regular expressions become a Web application developer's friend.
If that wasn't the cause of failure, the string is tested for too many characters—11 or more with . In the second pattern we are looking for a valid Java Script variable name of ten characters.
Java Script restricts the first character to letters, $, or an underscore.
Each test returns with an appropriate error message.
Note: all three functions use the beginning of string character, ^, and the end of string character, $.
Sometimes situations arise (input a phone number, zip code or credit card number) when the user should fill a single or more than one fields with numbers (0-9) in an HTML form.