Created
November 14, 2017 08:14
-
-
Save FahmiRaazali/814164dee022b0d6d530b98d55cdb418 to your computer and use it in GitHub Desktop.
[Regex Malaysia Mobile Phone Number] #regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /^(\+?6?01)[0|1|2|3|4|6|7|8|9]\-*[0-9]{7,8}$/ |
Author
Try this:
/^(\+?60)[0|1|2|3|4|6|7|8|9]\-*[0-9]{8,9}$/
- Select all phone numbers that start with +60 or 60
- Followed by a number between 0 and 9
- Followed by a dash or not
- Followed by 8 or 9 numbers between 0 and 9
Saya ada jumpa penjelasan kod yang tuan @semul kongsikan.
For a cleaner version and optional +60, use
/^(\+60)?[\d]\-*[\d]{8,9}$/
combining both ideas from @FahmiRaazali and @sagorzaii and also without repeating dashes. Also, removed the extra \ before dash to make it usable for HTML pattern attribute.
^(\+?6?01|\+?6?0)[0-9]-?[0-9]{7,8}$
This modified regex will match all the following numbers below:
012-3456789
+6012-3456789
6012-3456789
012-3456789
+603-12345678
03-12345678
03-12345678
0312345678
0123456789
01112345678
011-12345678
+6011-12345678
601112345678
60312345678
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this:
/^(\+?60)[0|1|2|3|4|6|7|8|9]\-*[0-9]{8,9}$/