Skip to content

Instantly share code, notes, and snippets.

@tungvn
Last active January 16, 2024 07:45
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save tungvn/2460c5ba947e5cbe6606c5e85249cf04 to your computer and use it in GitHub Desktop.
Save tungvn/2460c5ba947e5cbe6606c5e85249cf04 to your computer and use it in GitHub Desktop.
Vietnamese phone number Regex validation
/*
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);
}
@trishluan
Copy link

0912419333

@vnphanquang
Copy link

Thanks man!

@vovanvu
Copy link

vovanvu commented Dec 14, 2020

thanks!

@vnphanquang
Copy link

I think 05 (Vietnamobile) is a new accepted prefix. You should update the gist

@tungvn
Copy link
Author

tungvn commented Dec 16, 2020

I think 05 (Vietnamobile) is a new accepted prefix. You should update the gist

Yeah, I missed that. Updated.

@vanquyettran
Copy link

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!

@dieptang
Copy link

dieptang commented Mar 24, 2021

It will be great if you also add support phone like '+84xxxxxxxxx' or '84xxxxxxxxx'

@minhchien0207
Copy link

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);
}

@hphuocthanh
Copy link

hphuocthanh commented Sep 8, 2021

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)

@hungdev
Copy link

hungdev commented Oct 1, 2021

Thank guys. Nice your suggestion @dieptang. I also have that question.

@tyluudinh
Copy link

tyluudinh commented Oct 20, 2021

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

@quangld
Copy link

quangld commented Apr 12, 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

@sanghavp
Copy link

Cảm ơn anh!

@XuanManh9999
Copy link

Thanks anh

@thinhfullstack
Copy link

Cảm ơn anh ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment