Skip to content

Instantly share code, notes, and snippets.

@FahmiRaazali
Created November 14, 2017 08:14
Show Gist options
  • Select an option

  • Save FahmiRaazali/814164dee022b0d6d530b98d55cdb418 to your computer and use it in GitHub Desktop.

Select an option

Save FahmiRaazali/814164dee022b0d6d530b98d55cdb418 to your computer and use it in GitHub Desktop.
[Regex Malaysia Mobile Phone Number] #regex
/^(\+?6?01)[0|1|2|3|4|6|7|8|9]\-*[0-9]{7,8}$/
@killallskywalker
Copy link

terima kasih bro , jimat masa

@liongkj
Copy link

liongkj commented Jul 25, 2020

kasih

@winsonloh
Copy link

Thank you saved my time, Kasih lu satu like

@marcustut
Copy link

Thanks bro, this came in very handy!

@mzayn
Copy link

mzayn commented Jun 24, 2021

hi, bagi No yang 11 angka mcm mana nak match ya ?

contoh wajibkan letak angkan 6 di hadapan.

contoh 0123456789 - regex masih valid . kalau nak buat wajibkan telak angka 6 dihadapan mcm mana ya

@semul
Copy link

semul commented Nov 5, 2021

hi, bagi No yang 11 angka mcm mana nak match ya ?

contoh wajibkan letak angkan 6 di hadapan.

contoh 0123456789 - regex masih valid . kalau nak buat wajibkan telak angka 6 dihadapan mcm mana ya

Try this: /^(\+?60)[0|1|2|3|4|6|7|8|9]\-*[0-9]{8,9}$/

@FahmiRaazali
Copy link
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.

@sagorzaii
Copy link

For a cleaner version and optional +60, use
/^(\+60)?[\d]\-*[\d]{8,9}$/

@zrrtcs
Copy link

zrrtcs commented Oct 26, 2023

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