I’m trying to validate a field named phone_number with this rules:
the first digit should be 3 then another 9 digits so in total 10 number example: 3216549874
or can be 7 numbers 1234567
here i have my code:
if (!($("#" + val["htmlId"]).val().match(/^3\d{9}|\d{7}/)))
missing = true;
Why doesnt work 🙁 when i put that into an online regexp checker shows good.
You should be using test instead of match and here’s the proper code:
Match will find all the occurrences, while test will only check to see if at least one is available (thus validating your number).