A lightweight, zero-dependency utility library for validating and formatting Ethiopian mobile phone numbers.
Supports both Ethio Telecom and Safaricom.
npm install @eyuel_engida/ethio-helpersconst { isEthioPhone, formatEthioPhone } = require('@eyuel_engida/ethio-helpers');
// --- 1. Validation ---
// Checks if the number is a valid Ethio Telecom (09) or Safaricom (07) number
console.log(isEthioPhone('0911234567')); // true
console.log(isEthioPhone('+251712345678')); // true
console.log(isEthioPhone('0811234567')); // false (Invalid prefix)
console.log(isEthioPhone('0111550000')); // false (Landline)
// --- 2. Formatting ---
// Converts messy inputs into the standard international format: +251 9XX XXX XXX
const formatted = formatEthioPhone('0911223344');
console.log(formatted);
// Output: "+251 911 223 344"
const formattedSafaricom = formatEthioPhone('0712345678');
console.log(formattedSafaricom);
// Output: "+251 712 345 678"- β
Validation: Correctly identifies valid
09(Ethio Telecom) and07(Safaricom) prefixes - β
Flexible Input: Supports numbers with
+251,251,0, or no prefix - β Formatting: Auto-formats valid numbers into a clean, standardized UI-friendly format
- πͺΆ Zero Dependencies: Fast, lightweight, and dependency-free
Created by Eyuel
ISC
