6

The phone number should start with +65, followed by 6|8|9 with a total of 11 digits. For example: +6598798765

Michael M.
  • 10,486
  • 9
  • 18
  • 34

2 Answers2

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

KAD
  • 10,972
  • 4
  • 31
  • 73
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));
Sagar V
  • 12,158
  • 7
  • 41
  • 68