4

The Phone Number Should Start with +65, Followed By 6|8|9 with Total of 11 Digits For Ex : +6598798765

Thank You

1
  • 1
    Have you tried to solve this? If yes, edit the question and add the regex.
    – Tushar
    Feb 27, 2017 at 6:09

2 Answers 2

7
/\+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

6
  • Thank You! It Din't work :( Feb 27, 2017 at 6:10
  • The pattern error is a typo, I fixed the or selection @Tushar.
    – KAD
    Feb 27, 2017 at 6:12
  • This is Correct \+65[6|8|9]\d{7} Thanks Feb 27, 2017 at 6:16
  • The one in the answer is correct, the one you stated as correct may match a | character as @Tushar noted
    – KAD
    Feb 27, 2017 at 6:21
  • 1
    Are you sure 6 is the starting letter for Singapore mobile number? I know only 8 or 9 starting digit. Dec 6, 2018 at 8:10
0

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));

Not the answer you're looking for? Browse other questions tagged or ask your own question.