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

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

Naveen Kumar Thippirishetty
- 123
- 1
- 1
- 3
-
1Have you tried to solve this? If yes, [edit] the question and add the regex. – Tushar Feb 27 '17 at 06:09
2 Answers
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
-
-
-
-
The one in the answer is correct, the one you stated as correct may match a `|` character as @Tushar noted – KAD Feb 27 '17 at 06:21
-
1Are you sure 6 is the starting letter for Singapore mobile number? I know only 8 or 9 starting digit. – Yalamandarao Dec 06 '18 at 08:10
-
@Singapore - The answer was based on the numbers provided within the question, you may be right though... – KAD Dec 06 '18 at 12:31
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