A phone area code feels like a location stamp. It sits next to an address in the same form, it is often the only geographic-looking part of the number, and it is tempting to treat it as one more field to cross-check against a city. That instinct was reasonable decades ago and is unreliable now.
This article explains how international dialling codes and domestic area codes are actually structured, why mobile numbers and number portability break the geographic link, and what a consistency check between address and phone can honestly enforce in test data or in production.
Country code, area code and subscriber number
An international phone number has three parts: a country calling code, a national destination part that may include a regional area code, and the subscriber number. Country calling codes are short — one to three digits — and they are assigned as part of a global numbering plan, which is what makes international dialling predictable.
Inside a country, the structure of the national part is set by that country’s regulator, and it varies enormously. Some countries use a fixed-length national number with a regional prefix that is always the same length. Others use variable-length numbers, where the area code and the subscriber part trade digits depending on the region and the service. Some abbreviate the code when dialling domestically and require it when dialling from abroad.
Two consequences follow for anyone storing this data. First, the same number has several valid written forms, and they differ in more than punctuation: the international form may include a prefix that the domestic form omits, and the grouping of digits may change. Second, the total length of a number has a defined maximum but not a single global value, so a strict length rule will reject valid numbers from somewhere.
Is the area code still a location?
Weaker than it used to be, and weaker every year. Several ordinary developments erode the link between a number and a place.
- Mobile numbers often carry no geographic information at all. In many countries they are issued from blocks that are not tied to a region, so a number tells you nothing about where its owner is.
- Number portability lets a subscriber keep a number while moving between operators, and in several countries across regions as well. A number issued in one place can be in use somewhere else.
- Voice over internet calling decouples the number from any physical line. A number can be bought in one country and answered in another without the caller noticing.
- People move and keep their numbers. Fixed-line numbers are frequently retained after a move within the same country.
The accurate statement is that an area code records where a number was first issued, at best. It is not a current location, and it is not evidence of residence.
What can a consistency check actually enforce?
Not much, and knowing the limits is what makes the check useful. Three strengths are available, and they should be chosen deliberately.
A hard rule is one that can be enforced without false rejections: the number matches the expected shape for the stated country, it contains only the permitted characters, and its length is within the range that country permits. These are safe to enforce at the point of entry.
A soft signal is one worth surfacing but not blocking: the area code corresponds to a different region than the address, or the number is a mobile where the form implies a landline. These are worth a warning in an internal tool and never worth a hard failure on a public form.
A statistical guess — deriving a city from a number, or inferring an operator, and storing that as fact — is the one to avoid entirely. It will be wrong often enough to be harmful, and because the output looks like a clean field, nobody downstream will question it.
Why test data still needs the consistency check
Test data is where a loose geographic assumption does the most damage, because fixtures are built by hand and then trusted. If a fixture pairs a number from one country’s numbering plan with an address in another, every test that touches the number passes while testing nothing, and a real defect in the phone field stays hidden until production.
The useful checks for a fixture set are modest. The country calling code matches the address country. The number’s length and character set match the plan for that country. The national part is plausible for the type of number the field claims to hold. Anything beyond that — asserting that the area code maps to the city in the record — asserts something that is not true of real data either, and a fixture that enforces it trains the team on a false rule.
Fixtures should also include the awkward cases: a number written in international form and the same number in domestic form, a number with a regional code that does not match the address, and a mobile number with no regional information at all. The difference between those cases and the counterexamples is the point of the set. The shape of a well-organised fixture set is described in address data in test fixtures.
For developers: storage, grouping and display
Store the country calling code separately from the national number. The pair is unambiguous; a single field containing an international number in a locally conventional format is not, and every consumer then reimplements parsing to recover the parts.
Store the national number as a string of digits, without punctuation or grouping. Punctuation is a display concern, and grouping rules differ between countries and even between number types, so storing the grouped form locks in a formatting decision that will be wrong somewhere. Normalise on input, at one boundary, as with any identifier.
For display, keep the formatting rules per country alongside the country’s other conventions. And be careful with the international prefix — the plus sign and the digits that follow it are the only form that is globally unambiguous, while the prefix used to reach an international line varies by country and is not part of the number.
Finally, treat a phone number as personal data in the same way an address is. It identifies an individual, so the minimisation, retention and test-environment rules that apply to addresses apply here too. The shared obligations are set out in address data privacy. If your data also carries country codes, the pitfalls of the different forms are covered in ISO country and subdivision codes.
Next steps
Take the phone column in your schema and check three things: that the country code is stored separately, that the national part is text and unpunctuated, and that validation is limited to shape rather than geography. Then add one fixture where the number and the address deliberately come from different regions, and make sure your tests expect it to be accepted with a warning rather than rejected. Both the address and the number for a sample record are available in the address generator. That record is synthetic — assembled to exercise the form, not to place a call or deliver anything.