trying to use regex to validate that a string contains 9 or 12 digits (but not 10 or 11), currently using a list of two regexes and checking the input string twice. Can this be simplified?
var regexes = [/^[0-9]{9}$/, /^[0-9]{12}$/]
for (var i = 0; i < regexes.length; ++i) {
if (regexes[i].test(input))
return true;
}
return false;
You could use a regex like this:
So 9 digits, possibly followed by 3 more digits.
However, there is nothing wrong with checking two possibilities as you have.