• Skull giver@popplesburger.hilciferous.nl
    link
    fedilink
    arrow-up
    9
    ·
    edit-2
    11 hours ago

    Country codes are variable. Even the “I’m about to dial another country prefix” (usually + resolves to 00 but that depends on country and carrier) is variable. Phone number lengths are variable. Phone numbers are often written in non-Arabic numerals. Phone numbers can have specific digits in the middle of the number to reroute the call to another carrier.

    You can try to parse phone numbers if you’re writing a specific phone number parsing library, but you’ll need to keep up with the ITU documents, the numbering plans of all countries and satellite providers, and provide support for older standards going back to the 60s. You’ll need to deal with edge cases that your language probably doesn’t even have names for. And most importantly, you’ll have to guess what country the phone number is from based on context clues such as the user’s language or location or locale because phone numbers can be and are reused across borders.

    Phone numbers are worse than time zones. Don’t parse them yourself unless you’re building an international phone interconnect.