Sri Lanka Phone Numbers: Format, Area Code & Validation Guide
This guide provides a comprehensive overview of Sri Lanka's phone number system, offering developers essential information for building robust and compliant telecommunications applications. We'll cover number formatting, validation, carrier identification, Mobile Number Portability (MNP), emergency number handling, and best practices for implementation.
Quick Reference
- Country: Sri Lanka
- Country Code: +94
- International Prefix: 00
- National Prefix: 0
- Regulatory Body: Telecommunications Regulatory Commission of Sri Lanka (TRC) (http://www.trc.gov.lk)
Number Format and Validation
Sri Lankan phone numbers adhere to the ITU-T E.164 international standard. This standard defines a consistent format for international telephone numbers, ensuring global interoperability.
E.164 Format
The E.164 format consists of:
- Country Code: +94
- National Significant Number: A 9-digit number
Example: +94771234567
Number Types
Sri Lankan numbers can be categorized into the following types:
- Mobile: Typically begin with
070
,071
,072
,075
,076
,077
, or078
followed by 7 digits. - Landline: Begin with
0
followed by a 2-digit area code and a 7-digit subscriber number. Area codes range from 11 (Colombo) to 91 (Ampara). - Short Codes: These are typically 3 or 4 digits and used for special services. Examples include emergency numbers (119, 110, 1919) and other services.
Validation Best Practices
- Store in E.164: Always store phone numbers in the E.164 format (+94XXXXXXXXX) for consistency and ease of internationalization. This simplifies processing and ensures compatibility with various telecommunications systems.
- Validate User Input: Implement robust validation to ensure users enter correctly formatted numbers. Client-side validation enhances user experience, while server-side validation is crucial for security and data integrity.
- Regular Expression Validation: Use regular expressions to validate number formats. Here's an example using JavaScript:
function validateSriLankanNumber(number) {
// Remove all non-numeric characters
const cleaned = number.replace(/\D/g, '');
// Check for valid length and prefix
return /^(?:0|94|\+94)?([0-9]{9})$/.test(cleaned);
}
- Number Type Identification: You can identify the type of number based on the prefix:
function identifyNumberType(number) {
const cleaned = number.replace(/\D/g, '');
if (/^07[0-8][0-9]{7}$/.test(cleaned)) return 'mobile';
if (/^0[1-9][0-9]{7}$/.test(cleaned)) return 'landline';
if (/^1[0-9]{2,3}$/.test(cleaned)) return 'short code'; // Or 'special'
return 'invalid';
}
Mobile Number Portability (MNP)
MNP allows subscribers to switch operators while keeping their existing number. This requires developers to implement lookup mechanisms to determine the current operator for a given number.
- MNP Lookup Service: Integrate with an MNP lookup service (if available) to dynamically determine the correct operator. This is crucial for accurate routing and billing.
async function checkOperatorForNumber(phoneNumber) {
try {
const response = await mnpLookupService.query(phoneNumber);
return response.currentOperator;
} catch (error) {
console.error('MNP lookup failed:', error);
return null; // Handle lookup failures gracefully
}
}
- Routing Considerations: Use the identified operator information to route calls and messages correctly. This ensures efficient delivery and minimizes potential disruptions.
const routeCall = async (phoneNumber) => {
const operator = await checkOperatorForNumber(phoneNumber);
return getRoutingPath(operator); // Define routing logic based on operator
};
Emergency Numbers
Handle emergency numbers with care. Directly dial these numbers without any prefixes.
- Common Emergency Numbers:
- Police: 119
- Ambulance: 110
- Disaster Management: 1919
- Emergency Number Detection: Implement logic to identify emergency numbers and handle them appropriately.
const EMERGENCY_NUMBERS = ['119', '110', '1919'];
function isEmergencyNumber(number) {
return EMERGENCY_NUMBERS.includes(number);
}
Network Considerations
Sri Lanka's network infrastructure is a mix of modern urban and developing rural networks. Consider these factors when designing your application:
- Network Detection and Fallback: Implement network quality detection and provide fallback mechanisms for poor connections. This ensures a usable experience even in areas with limited connectivity.
function checkNetworkCapability() {
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
if (connection) {
return connection.effectiveType; // Use effectiveType for a general assessment
}
return 'unknown'; // Default to unknown if connection information is unavailable
}
- Coverage-Aware Features: Design features that adapt to varying network conditions. Consider caching, adaptive bitrate streaming, and offline functionality.
Compliance and Regulations
Adhere to the regulations set by the TRC. Key aspects include:
- Number Formatting: Strictly adhere to E.164 for storage and international calls. Use local formatting for display purposes only.
- Device Approval: Be aware of device approval requirements for importing mobile devices (https://www.trc.gov.lk/pages_e.php?id=63).
- Licensing: Understand the licensing requirements for telecommunications operations (https://www.trc.gov.lk/legislation/pages_e.php?id=34).
Error Handling
Implement comprehensive error handling to manage various scenarios, such as invalid number formats, MNP lookup failures, and network issues. Provide informative error messages and logging for debugging and monitoring.
// Example error handling
try {
// Your code here
} catch (error) {
console.error("An error occurred:", error);
// Implement appropriate error handling logic
}
Additional Resources
- TRC Website: http://www.trc.gov.lk
- Sri Lanka Telecommunications Act: https://www.srilankalaw.lk/revised-statutes/volume-vii/1212-sri-lanka-telecommunications-act.html
By following these guidelines, you can develop telecommunications applications that are robust, compliant, and optimized for the Sri Lankan market. Remember to consult the TRC website for the latest regulations and updates.