In JavaScript numbers can be validated to be of a certain length. For example, the following regular expression can be used to validate that a numeric value is two digits in length:
document.write(/^\d\d$/.test(22));
This simply calls the \d character class twice. Using curly braces {} this statement can be made even simpler:
document.write(/^\{2}$/.test(22));
The curly braces specify that [...]
Filed under: Internet, JavaScript, Programming, Software, Web | 3 Comments »