2 changed files with 195 additions and 17 deletions
@ -0,0 +1,61 @@ |
|||
|
|||
function verification(countryCode,phoneNumber) { |
|||
switch (countryCode) { |
|||
case '+86': |
|||
return verificationChina(phoneNumber); |
|||
case '+1': |
|||
return verificationAmerica(phoneNumber); |
|||
case '+65': |
|||
return verificationSingapore(phoneNumber); |
|||
case '+60': |
|||
return verificationMalaysia(phoneNumber); |
|||
case '+66': |
|||
return verificationThailand(phoneNumber); |
|||
case '+852': |
|||
return verificationHongKong(phoneNumber); |
|||
case '+84': |
|||
return verificationVietnam(phoneNumber); |
|||
default: |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
|
|||
function verificationChina(phoneNumber){ |
|||
const phoneRegex = /^1[3-9]\d{9}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
|
|||
|
|||
function verificationAmerica(phoneNumber){ |
|||
const phoneRegex = /^[2-9]\d{2}[- ]?\d{4}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
function verificationSingapore(phoneNumber){ |
|||
const phoneRegex = /^[89]\d{7}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
function verificationMalaysia(phoneNumber){ |
|||
const phoneRegex = /^01\d{8}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
|
|||
function verificationHongKong(phoneNumber){ |
|||
const phoneRegex = /^0[896]\d{8}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
|
|||
|
|||
function verificationThailand(phoneNumber){ |
|||
const phoneRegex = /^[5-9]\d{7}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
|
|||
|
|||
|
|||
function verificationVietnam(phoneNumber){ |
|||
const phoneRegex = /^(0)?[3-9]\d{8}$/; |
|||
return phoneRegex.test(phoneNumber); |
|||
} |
|||
|
|||
export {verification} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue