phone number standards
phone number standards
Kenya Phone Number Format: +254 Country Code, Validation & Prefixes
Master Kenya phone numbers with +254 country code. Covers validation regex, E.164 format, Safaricom/Airtel/Telkom prefixes, area codes, MNP implementation, and emergency numbers for developers.
Kenya Phone Numbers: Format, Validation & +254 Country Code Guide
Kenya phone numbers use the +254 country code and follow the ITU-T E.164 international standard for formatting. This guide provides developers with a comprehensive framework for validating and integrating Kenya's phone numbering system. You'll learn how to validate mobile numbers for Safaricom, Airtel, Telkom, and Equitel, implement Mobile Number Portability (MNP), parse landline area codes, and handle emergency services correctly.
Kenya Phone Number Structure: E.164 Standard Explained
Kenya adheres to the international E.164 phone number format standard (version 11/2010, with amendments through 06/2020), a globally recognized framework for telephone numbering. This standard ensures consistency and interoperability in international telecommunications, which is essential when building applications that handle phone validation, SMS delivery, or call routing across borders.
The E.164 standard defines a hierarchical structure for phone numbers, starting with the country code, followed by the National Significant Number (NSN). The NSN is further divided into the National Destination Code (NDC) and the subscriber number. In Kenya, the country code is +254, and the NSN is 9 digits long.
graph LR
A[Full Number (E.164)] --> B[Country Code (+254)]
A --> C[National Significant Number (NSN - 9 digits)]
C --> D[National Destination Code (NDC - 2 or 3 digits)]
C --> E[Subscriber Number (SN - 6 or 7 digits)]
D --> F[Landline (2 digits)]
D --> G[Mobile (3 digits)]This structure is essential for routing calls and messages correctly. Let's break down the specific formats for landline and mobile numbers in Kenya.
Kenya Landline Phone Numbers: Area Codes by City
Landline numbers in Kenya follow a predictable 9-digit format, comprising a 2-digit area code and a 7-digit subscriber number. You should familiarize yourself with this structure to ensure accurate parsing and validation within your systems.
Format: 0[Area Code][Subscriber Number]
Example: 020 1234567
↓↓ ↓↓↓↓↓↓↓ Subscriber Number (7 digits)
└└─ Area Code (2 digits)The leading "0" is the trunk prefix, used for domestic dialing within Kenya. When dialing internationally, this "0" is omitted, and the country code (+254) is prepended.
Here's a table outlining some common area codes for major cities:
| Region | Area Code | Example Number | Usage Pattern |
|---|---|---|---|
| Nairobi | 020 | 0201234567 | Metropolitan |
| Mombasa | 041 | 0411234567 | Coastal |
| Kisumu | 057 | 0571234567 | Regional |
| Eldoret | 053 | 0531234567 | Regional |
| Nakuru | 051 | 0511234567 | Regional |
This is not an exhaustive list, and you should consult the Communications Authority of Kenya (CA) for a complete list of area codes. Consider using a lookup table or API to dynamically retrieve area code information, ensuring your application remains up-to-date with any changes.
How to Validate Kenya Mobile Numbers: Safaricom, Airtel, Telkom & Equitel Prefixes
Mobile numbers in Kenya are 10 digits long, starting with a 3-digit mobile prefix followed by a 7-digit subscriber number. Understanding these prefixes is crucial for identifying the mobile network operator (MNO). The major telecommunications providers in Kenya include Safaricom (the largest operator), Airtel Kenya, Telkom Kenya, and Equitel.
function validateKenyanMobile(number) {
const regex = /^0[17][0-9]{8}$/; // Includes prefixes starting with 1 (introduced May 2019)
const prefixRanges = {
safaricom: /^0[17][0-9]{2}/,
airtel: /^073[0-9]/,
telkom: /^077[0-9]/,
equitel: /^0763[0-9]{2}/
};
return {
isValid: regex.test(number),
carrier: determineCarrier(number, prefixRanges)
};
function determineCarrier(number, prefixRanges) {
for (const carrier in prefixRanges) {
if (prefixRanges[carrier].test(number)) {
return carrier;
}
}
return 'unknown';
}
}
// Example test cases
console.log(validateKenyanMobile('0722123456')); // Safaricom, valid
console.log(validateKenyanMobile('0110123456')); // Safaricom, valid (new prefix)
console.log(validateKenyanMobile('0730123456')); // Airtel, valid
console.log(validateKenyanMobile('0770123456')); // Telkom, valid
console.log(validateKenyanMobile('0763123456')); // Equitel, valid
console.log(validateKenyanMobile('0700123456')); // Unknown, valid (could be a new operator)
console.log(validateKenyanMobile('072212345')); // Invalid (too short)
console.log(validateKenyanMobile('0800123456')); // Invalid (not a mobile prefix)
Adapt this code to your specific needs, adding more prefixes and validation rules as required. Handle edge cases, such as invalid prefixes or incorrect number lengths. If the validateKenyanMobile function encounters a number with a valid length but an unknown prefix, it returns 'unknown' for the carrier while still indicating the number is valid, since new operators or number ranges might be introduced.
Important: In May 2019, the Communications Authority of Kenya introduced mobile prefixes starting with the digit 1. You should regularly update your validation patterns to accommodate new number ranges allocated by the CA. This proactive approach ensures your application remains compatible with the evolving Kenyan numbering system.
How to Implement Mobile Number Portability (MNP) in Kenya
Mobile Number Portability (MNP) allows subscribers to switch operators while keeping their existing number. Kenya's MNP implementation follows ITU-T E.164 Supplement 2 (updated June 2020) guidelines. You'll need to integrate with the central MNP database to verify the current operator of a ported number.
Real-time MNP Validation
Real-time validation is crucial for ensuring accurate routing and billing. Integrate with the central MNP database via an API to query the current operator of a given number.
def check_ported_number(msisdn):
# Connect to MNP database (replace with actual connection details)
mnp_db = MNPDatabase.connect(db_host='mnp_db_host', db_user='mnp_user', db_password='mnp_password')
try:
# Query current carrier
current_carrier = mnp_db.query_carrier(msisdn)
# Check porting status
porting_status = mnp_db.get_porting_status(msisdn)
return {
'original_carrier': determine_original_carrier(msisdn),
'current_carrier': current_carrier,
'is_ported': porting_status.is_ported,
'port_date': porting_status.port_date
}
except (ConnectionError, DatabaseError) as e:
# Handle database connection or query errors
logger.error(f"MNP database error: {e}")
# Implement fallback mechanism (e.g., assume original carrier)
return {'original_carrier': determine_original_carrier(msisdn), 'current_carrier': None, 'is_ported': False, 'port_date': None}
finally:
mnp_db.close() # Close the database connection
def determine_original_carrier(msisdn):
# Logic to determine original carrier based on prefix (before porting)
# ... (similar to the JavaScript example)
passThis revised code includes error handling and a fallback mechanism. In case of database connectivity issues, the function logs the error and returns a dictionary indicating that the number's current carrier is unknown, allowing your application to gracefully handle such situations. Always implement fallback mechanisms for MNP database connectivity issues to ensure service continuity.
MNP Database Synchronization
Regular synchronization with the central MNP database is essential for maintaining accurate number information. Implement a robust synchronization process that handles potential errors and ensures data integrity.
┌──────────────────┐ ┌─────────────────┐ ┌──────────────────┐
│ Your Database │ ─── Synchronization ─── │ MNP Central DB │ ─── │ Carrier Systems │
└──────────────────┘ └─────────────────┘ └──────────────────┘The frequency of synchronization depends on porting activity volume and your specific requirements. Consider using a delta synchronization approach to minimize data transfer and improve efficiency. This involves only synchronizing changes since the last synchronization, rather than the entire database.
MNP Implementation Timeline and Considerations
Kenya's MNP framework has evolved over time. Here are key milestones:
- 2011: Initial MNP implementation launched by the CA. This marked a significant step towards fostering competition in the Kenyan telecommunications market. Early challenges included technical issues and inter-operator disputes.
- 2016: Major system upgrades and process streamlining implemented to improve efficiency and reliability.
- 2018: CA published revised MNP guidelines providing a detailed regulatory framework.
- 2019: Enhanced verification protocols introduced to prevent unauthorized porting and strengthen consumer protection.
- 2020: ITU-T E.164 Supplement 2 updated with international best practices for number portability.
When implementing MNP, consider these factors:
- Consumer Protection: The CA enforces strict verification requirements to prevent unauthorized porting. Ensure your implementation adheres to these requirements. Subscribers must provide valid identification and authorization before porting requests are processed.
- Inter-operator Agreements: Operators maintain service level agreements (SLAs) that govern the porting process, typically requiring completion within 3–5 business days. Familiarize yourself with these agreements to ensure compliance.
- Dispute Resolution: The CA provides a framework for resolving MNP-related disputes. Contact the CA at chukuahatua@ca.go.ke for consumer complaints or info@ca.go.ke for regulatory inquiries.
Kenya Emergency Numbers: 999, 112, and Special Service Numbers
Emergency numbers require special handling in your system. Prioritize routing for these numbers and bypass any credit checks or other restrictions.
const EMERGENCY_NUMBERS = {
GENERAL: '999', // Primary emergency number (CA designated)
ALTERNATIVE: '112', // International emergency number
POLICE: '911', // Police emergency
FIRE: '990', // Fire emergency
AMBULANCE: '991' // Ambulance emergency
};
function handleEmergencyCall(number) {
if (Object.values(EMERGENCY_NUMBERS).includes(number)) {
// Priority routing
// Bypass credit checks
// Enable location services (if applicable)
console.log(`Routing emergency call to ${number}`);
return true;
}
console.log(`Number ${number} is not an emergency number`);
return false;
}
// Example test cases
handleEmergencyCall('999'); // Routes emergency call
handleEmergencyCall('112'); // Routes emergency call
handleEmergencyCall('911'); // Routes emergency call
handleEmergencyCall('990'); // Routes emergency call
handleEmergencyCall('991'); // Routes emergency call
handleEmergencyCall('0722123456'); // Not an emergency numberIntegrate this with your call routing and emergency service protocols. Emergency calls must be processed immediately, regardless of account status or credit balance.
Best Practices for Kenya Phone Number Validation and Formatting
Implementing best practices ensures your application handles Kenyan phone numbers efficiently and reliably.
Converting Kenya Numbers to International Format (+254)
Convert local numbers to international format for international calls and SMS. This is essential for ensuring proper routing in global telecommunications systems and SMS delivery across international carriers.
function toInternationalFormat(localNumber) {
// Remove leading zero and any spaces or hyphens
const normalized = localNumber.replace(/^0/, '').replace(/[\s-]/g, '');
// Add country code
return `+254${normalized}`;
}
// Example test cases
console.log(toInternationalFormat('0722 123 456')); // +254722123456
console.log(toInternationalFormat('020-1234567')); // +254201234567This function handles various input formats, removing spaces and hyphens before adding the country code. This ensures consistency and avoids potential errors.
Phone Number Validation with Regular Expressions
Robust validation prevents errors and ensures data integrity. Use regular expressions to validate number formats and identify potential issues.
const validationPatterns = {
landline: /^0(20|41|[4-6][0-9])[0-9]{7}$/,
mobile: /^0[17][0-9]{8}$/, // Includes prefixes starting with 1 (May 2019+)
tollFree: /^0800[0-9]{6}$/,
premium: /^0900[0-9]{6}$/
};
function validateNumber(number, type) {
if (!validationPatterns[type]) {
return false; // Invalid type
}
return validationPatterns[type].test(number);
}
// Example test cases
console.log(validateNumber('0201234567', 'landline')); // True
console.log(validateNumber('0722123456', 'mobile')); // True
console.log(validateNumber('0110123456', 'mobile')); // True (new prefix)
console.log(validateNumber('0800123456', 'tollFree')); // True
console.log(validateNumber('0900123456', 'premium')); // True
console.log(validateNumber('072212345', 'mobile')); // False (too short)
console.log(validateNumber('0201234567', 'mobile')); // False (wrong type)
Extend this function to include additional validation rules as needed. Update validation patterns regularly to accommodate new number ranges allocated by the CA.
Premium and Special Number Management
Premium or "golden" numbers, often featuring repeating or sequential digits, are highly sought after by businesses. These numbers enhance brand recognition and customer recall. The CA manages allocation through a structured application and evaluation process. VIP number ranges are maintained for government and security institutions.
Toll-free numbers (starting with 0800) and premium-rate numbers (starting with 0900) follow specific formats and have distinct billing rules. Ensure your application properly identifies and handles these special number types for accurate call routing and billing. Learn more about implementing 10DLC SMS registration for US-based business messaging.
Frequently Asked Questions
What is Kenya's country code for international calls? Kenya's international dialing code is +254. To call Kenya from abroad, dial +254 followed by the local number without the leading 0. For example, a Nairobi landline 020 1234567 becomes +254 20 1234567 internationally.
How do I validate a Kenyan mobile number in code?
Kenyan mobile numbers are 10 digits long and start with prefixes like 07XX or 01XX. Use the regex pattern /^0[17][0-9]{8}$/ to validate the format. For carrier identification, check against known operator prefixes: Safaricom (0[17]XX), Airtel (073X), Telkom (077X), and Equitel (0763).
What are the main mobile operators in Kenya? The major mobile network operators are Safaricom (largest market share), Airtel Kenya, Telkom Kenya, and Equitel.
How does Mobile Number Portability work in Kenya? MNP allows subscribers to change operators while keeping their number. The porting process typically takes 3–5 business days and requires verification through the CA-regulated central database.
Conclusion: Implementing Kenya Phone Number Systems
This guide has equipped you with the essential knowledge and practical tools to confidently handle Kenyan phone numbers in your applications. By implementing proper validation for mobile and landline formats, integrating MNP support, and following E.164 standards, you can ensure your applications are robust, compliant, and provide a seamless experience for your users.
For the most up-to-date information on Kenya's numbering plan, area codes, and regulatory changes, consult the Communications Authority of Kenya website and official documentation.