Skip to content

Instantly share code, notes, and snippets.

@tungvn
Last active September 18, 2024 16:02
Show Gist options
  • 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);
}
@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 ^^

@datpp-ct
Copy link

datpp-ct commented Jun 26, 2024

/(?:\+84|0084|0)[235789][0-9]{1,2}[0-9]{7}(?:[^\d]+|$)/g -> updated Jun 26 2024 for phone & mobile phone

@RinNguyens
Copy link

/(?:\+84|0084|0)[235789][0-9]{1,2}[0-9]{7}(?:[^\d]+|$)/g -> updated Jun 26 2024 for phone & mobile phone

nice

@longnh299
Copy link

thank a lot!

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