Singapore Mobile Number RegEx [closed]

巧了我就是萌 提交于 2021-01-28 08:15:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!