Last active
September 18, 2024 16:02
-
-
Save tungvn/2460c5ba947e5cbe6606c5e85249cf04 to your computer and use it in GitHub Desktop.
Vietnamese phone number Regex validation
This file contains 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
/* | |
Before Septemper 15 2018, Vietnam has phone number start with 09*, 01(2|6|8|9). | |
After that, the phone number can start with 03, 05, 07 or 08. | |
So this function provide a way to validate the input number is a Vietnamese phone number | |
*/ | |
function isVietnamesePhoneNumber(number) { | |
return /(03|05|07|08|09|01[2|6|8|9])+([0-9]{8})\b/.test(number); | |
} |
Thank guys. Nice your suggestion @dieptang. I also have that question.
Updated: 20/10/2021
My regex:
const isValidPhone = phone => /^(0?)(3[2-9]|5[6|8|9]|7[0|6-9]|8[0-6|8|9]|9[0-4|6-9])[0-9]{7}$/.test(phone)
Updated: 13/09/2022
const isValidPhone = phone => /(([03+[2-9]|05+[6|8|9]|07+[0|6|7|8|9]|08+[1-9]|09+[1-4|6-9]]){3})+[0-9]{7}\b/g.test(phone)
isValidPhone('783728642364287323437894534')
> true
Cảm ơn anh!
Thanks anh
Cảm ơn anh ^^
/(?:\+84|0084|0)[235789][0-9]{1,2}[0-9]{7}(?:[^\d]+|$)/g
-> updated Jun 26 2024 for phone & mobile phone
/(?:\+84|0084|0)[235789][0-9]{1,2}[0-9]{7}(?:[^\d]+|$)/g
-> updated Jun 26 2024 for phone & mobile phone
nice
thank a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found that +8 | 4 plus any numbers (and old number format) still work even though it's not the right format.
So here's my regex: supporting +84, 84, 0084, or 0 as the prefix:
e.g: 0084957507468 | +84957507468 | 84957507468 | 0957507468 (idk who this number is)