Each test returns with an appropriate error message.Note: all three functions use the beginning of string character, ^, and the end of string character, $.After ensuring there is data, the next basic test is if there is the right amount of data.
Instead, the pattern specifies the first character is a letter followed by nine characters that can be letters, digits or a dash. preceded with a back virgule or solidus (\), because it has special meaning inside square brackets as a range separator.
One line can do a complete pattern test that would required more extensive loops and branches using string methods.
The most fundamental test is whether or not the field has data. It uses the character set [a-z] in combination with the case insensitive flag i and the to require three letters together.
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.