Check phone number activity, carrier details, line type and more.
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.
Sri Lankan numbers can be categorized into the following types:
Mobile: Typically begin with 070, 071, 072, 075, 076, 077, or 078 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:
functionvalidateSriLankanNumber(number){// Remove all non-numeric charactersconst cleaned = number.replace(/\D/g,'');// Check for valid length and prefixreturn/^(?:0|94|\+94)?([0-9]{9})$/.test(cleaned);}
Number Type Identification: You can identify the type of number based on the prefix:
functionidentifyNumberType(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.
Routing Considerations: Use the identified operator information to route calls and messages correctly. This ensures efficient delivery and minimizes potential disruptions.
constrouteCall=async(phoneNumber)=>{const operator =awaitcheckOperatorForNumber(phoneNumber);returngetRoutingPath(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.
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.
functioncheckNetworkCapability(){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.
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 handlingtry{// Your code here}catch(error){console.error("An error occurred:", error);// Implement appropriate error handling logic}
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.