Check phone number activity, carrier details, line type and more.
Portugal Phone Numbers: Format, Area Code & Validation Guide
Introduction
You're building an application that interacts with Portuguese phone numbers. Whether it's validating user input, managing customer data, or integrating with telecommunications APIs, accurate handling of these numbers is crucial. This guide provides the technical specifications, practical guidance, and best practices you need to confidently navigate the Portuguese telephone numbering system.
Quick Facts: A Starting Point
Before we dive into the details, let's establish some fundamental facts about Portuguese phone numbers:
Country: Portugal
Country Code: +351
International Prefix (from Portugal): 00
National Prefix: None (removed in 1999 for a closed numbering plan)
Regulatory Authority: ANACOM (Autoridade Nacional de Comunicações) - https://www.anacom.pt/
This shift to a closed numbering plan in 1999 simplified the system, making all calls within Portugal require nine digits, regardless of whether they are local or long-distance. This is a key detail to keep in mind as you design your application.
Number Structure: Decoding the 9-Digit Format
Portugal adheres to the ITU-T E.164 recommendation, ensuring international compatibility. ANACOM, the national regulatory body, enforces strict compliance with this standard. All Portuguese subscriber numbers follow a consistent 9-digit structure:
Country Code (+351): Identifies Portugal in international calls. Your application should handle both the '+' and '00' prefixes (e.g., +351 and 00351) for maximum flexibility.
Area/Service Code (2/9/8/6): The first digit of this two-digit code categorizes the number type (geographic, mobile, or special service).
Subscriber Number (XXXXXXX): The unique 7-digit identifier within the given area or service code.
Number Categories and Implementation Guidelines: Handling Different Number Types
Understanding the different categories of Portuguese phone numbers is essential for accurate validation and processing. Here's a detailed breakdown:
1. Geographic Numbers (Landlines): Connecting to Fixed Lines
Format:2X XXXXXXX
Area Code Distribution:
21: Lisbon metropolitan area
22: Porto metropolitan area
23x-29x: Other regions (specific allocations are available on ANACOM's website)
Implementation Note: You should always validate area codes against the most current ANACOM allocation tables to ensure accuracy. Hardcoding these values can lead to errors as allocations can change.
2. Mobile Numbers: Reaching Mobile Subscribers
Format:9X XXXXXXX
Operator Prefixes (Historically): While prefixes like 91 (Vodafone), 93 (NOS), and 96 (MEO) once indicated the original operator, number portability makes these unreliable.
Best Practice: Due to number portability, you should implement a portability check (as described later) before making assumptions about the current operator. This is crucial for accurate routing and billing.
3. Special Services: Understanding Unique Number Ranges
Toll-Free:800 XXXXXX - Free for the caller.
Shared Cost:808 XXXXXX - Cost is split between caller and recipient.
Premium:6XX XXXXX - Higher calling rates, often used for value-added services.
Warning: When handling premium-rate numbers, always provide clear notifications to users about potential charges and obtain explicit consent before initiating calls. This is a legal and ethical requirement.
As highlighted in the Additional Context, other special number ranges exist (e.g., 30x for VoIP carriers, 7xx for private networks), so consult ANACOM's documentation for a complete list.
Validation Implementation: Ensuring Data Integrity
Robust validation is paramount. Here's a refined validation approach using regular expressions:
const portugalPhoneValidation ={// Geographic (Landline)landline:/^2\d{8}$/,// Mobilemobile:/^9[1236]\d{7}$/,// Special Services (Partial - consult ANACOM for full list)tollFree:/^800\d{6}$/,sharedCost:/^808\d{6}$/,premium:/^6[046]\d{5}$/,// Full validation with optional country code (handles +351 and 00351)international:/^(?:\+351|00351)?[269]\d{8}$/};// Usage ExamplefunctionvalidatePortugueseNumber(number, type ='any'){// Clean the number (remove whitespace and other non-digit characters)const cleaned = number.replace(/\D/g,'');if(type ==='any'){returnObject.values(portugalPhoneValidation).some(regex=> regex.test(cleaned));}return portugalPhoneValidation[type]?.test(cleaned)||false;}// Example Test Casesconsole.log(validatePortugueseNumber('+351912345678','mobile'));// trueconsole.log(validatePortugueseNumber('21 123 45 67','landline'));// trueconsole.log(validatePortugueseNumber('00351211234567'));// trueconsole.log(validatePortugueseNumber('12345'));// false
This code provides a more robust cleaning process and includes example test cases to demonstrate its usage. Remember to test your validation logic thoroughly with various valid and invalid inputs, including edge cases.
Implementation Best Practices: Building a Robust System
Beyond basic validation, consider these best practices for a truly robust implementation:
1. Number Storage: The E.164 Standard
Always store phone numbers in E.164 format (+351XXXXXXXXX). This ensures consistency and simplifies international interactions.
// Format to E.164constformatToE164=(number)=>{const cleaned = number.replace(/\D/g,'');return cleaned.startsWith('351')?`+${cleaned}`:`+351${cleaned}`;};
This function now handles cases where the user might input the country code or not.
2. Display Formatting: Enhancing User Experience
Format numbers for display according to local conventions (XX XXX XXXX). This improves readability for your users.
constformatForDisplay=(number)=>{// Remove country code and formatconst local = number.replace(/^\+351/,'');return local.replace(/(\d{2})(\d{3})(\d{3,4})/,'$1 $2 $3');// Handles 5 or 6 digit subscriber numbers for special services};
This updated formatting function now correctly handles the varying lengths of subscriber numbers for different service types.
3. Number Portability Handling: Dealing with Operator Changes
Number portability allows users to keep their number when switching operators. You must account for this:
classPortabilityCheck{asynccheckOperator(number){// Implement ANACOM's portability database check (replace with actual API call)try{const operatorInfo =awaitthis.queryPortabilityDatabase(number);return{currentOperator: operatorInfo.operator,originalOperator:this.getOriginalOperator(number),// Useful for historical datalastPortedDate: operatorInfo.portedDate};}catch(error){console.error("Error checking portability:", error);// Handle error gracefully (e.g., fallback to original operator or return null)returnnull;}}// This function is now less reliable due to portability but can still provide a hintgetOriginalOperator(number){const prefix = number.substr(2,2);// Extract prefix after area codeconst operators ={'91':'Vodafone','93':'NOS','96':'MEO'};return operators[prefix]||'Unknown';}// Placeholder for actual API call (replace with your implementation)asyncqueryPortabilityDatabase(number){// Simulate API call (replace with your actual implementation)returnnewPromise((resolve)=>{setTimeout(()=>{resolve({operator:'NOS',portedDate:'2025-05-10'});},500);});}}
This improved code includes error handling and a placeholder for the actual API call to ANACOM's portability database, which you'll need to implement based on their specifications. As mentioned in the Additional Context, number portability is a key aspect of the Portuguese telecommunications landscape, and ANACOM provides resources and regulations related to this process.
Technical Considerations: Key Factors for Success
You've now learned the core concepts. Let's turn to some crucial technical considerations:
1. Error Handling: Gracefully Managing Issues
Implement robust error handling throughout your application. Provide clear and informative error messages to users and log errors for debugging. Consider regional variations in area codes and handle potential discrepancies gracefully.
2. International Integration: Ensuring Global Compatibility
Always support both +351 and 00351 prefixes for international calls. Consistently use E.164 formatting for storage and internal processing. Be mindful of specific requirements for SMS and voice APIs.
3. Regulatory Compliance: Staying Up-to-Date
Maintain up-to-date area code mappings and implement any required consumer protection measures, especially for premium-rate numbers. Regularly consult ANACOM's official documentation for the latest regulations and updates.
Conclusion: Putting it All Together
You now have a comprehensive understanding of Portuguese phone number formatting, validation, and best practices. By following this guide, you can build robust and reliable applications that seamlessly interact with the Portuguese telecommunications system. Remember to prioritize accuracy, user experience, and regulatory compliance. For the most current information and regulatory updates, always refer to ANACOM's official resources.