Created
September 20, 2018 11:15
-
-
Save giautm/b7d333c2ca8c6c05105179c126162a93 to your computer and use it in GitHub Desktop.
VN phone carriers detector
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
const MOBILE_REGEXP = /^(\+84|0)(3[2-9]|5[2689]|7[06-9]|8[1-5])[0-9]{7}$/ | |
const PREFIX_CARRIERS = { | |
viettel: ["32","33","34","35","36","37","38","39"], | |
mobifone: ["70","79","77","76","78"], | |
vinaphone: ["83","84","85","81","82"], | |
vietnamobile: ["52","56","58"], | |
gmobile: ["59"] | |
}; | |
function phoneCarrier(phone) { | |
const matches = (phone || '').match(MOBILE_REGEXP) | |
if (matches !== null) { | |
return Object.keys(PREFIX_CARRIERS) | |
.find(prefix => PREFIX_CARRIERS[prefix].includes(matches[2])) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment