问题
The Phone Number Should Start with +65, Followed By 6|8|9 with Total of 11 Digits For Ex : +6598798765
Thank You
回答1:
/\+65(6|8|9)\d{7}/g
\+ matches the character + literally (case sensitive)
65 matches the characters 65 literally (case sensitive)
1st Capturing Group (6|8|9)
- 1st Alternative 6 (6 matches the character 6 literally (case sensitive))
- 2nd Alternative 8 (8 matches the character 8 literally (case sensitive))
- 3rd Alternative 9 (9 matches the character 9 literally (case sensitive))
\d{7} matches a digit (equal to [0-9])
{7} Quantifier — Matches exactly 7 times
回答2:
You should use the cap(^) to indicate start of a string and EOS($) to specify the end of string.
var re=/^\+65(6|8|9)\d{7}$/;
var true_mob = "+6561234567";
var false_mob = "+6512345678";
console.log(re.test(true_mob));
console.log(re.test(false_mob));
来源:https://stackoverflow.com/questions/42478799/singapore-mobile-number-regex