UNPKG

nigeria-validator

Version:

Validate and format common Nigerian data: phone numbers, BVNs, bank codes, etc.

51 lines (42 loc) 1.05 kB
function getNigerianNetwork(phone) { const cleaned = phone.replace(/\D/g, ""); let normalized = cleaned; if (cleaned.startsWith("234")) { normalized = "0" + cleaned.slice(3); } // Get the first 4 digits const prefix = normalized.slice(0, 4); const mtnPrefixes = [ "0803", "0806", "0703", "0706", "0810", "0813", "0814", "0816", "0903", "0906", "0913", "0916", ]; const gloPrefixes = ["0805", "0705", "0811", "0815", "0905", "0915"]; const airtelPrefixes = [ "0802", "0808", "0708", "0812", "0701", "0902", "0907", "0901", "0912", ]; const etisalatPrefixes = ["0809", "0817", "0818", "0909", "0908"]; if (mtnPrefixes.includes(prefix)) return "MTN"; if (gloPrefixes.includes(prefix)) return "Glo"; if (airtelPrefixes.includes(prefix)) return "Airtel"; if (etisalatPrefixes.includes(prefix)) return "9mobile"; return "Unknown Network"; } module.exports = getNigerianNetwork