-
-
Save tungvn/2460c5ba947e5cbe6606c5e85249cf04 to your computer and use it in GitHub Desktop.
/* | |
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); | |
} |
This regex is not correct:
01|43694807 is valid
Please update:
[2|6|8|9]
--> [2689]
And I don't know the role of \b
, please give some information?
Thank you!
It will be great if you also add support phone like '+84xxxxxxxxx' or '84xxxxxxxxx'
It will be great you you also add support phone like '+84xxxxxxxxx' or '84xxxxxxxxx'
i think this is version update you want:
function isVietnamesePhoneNumber(number) {
return /([\+84|84|0]+(3|5|7|8|9|1[2|6|8|9]))+([0-9]{8})\b/.test(number);
}
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:
function isVietnamesePhoneNumber(number) {
return /((^(\+84|84|0|0084){1})(3|5|7|8|9))+([0-9]{8})$/.test(number);
}
e.g: 0084957507468 | +84957507468 | 84957507468 | 0957507468 (idk who this number is)
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!
Yeah, I missed that. Updated.