[tpm] Regex to validate (international) phone numbers

Liam R E Quin liam at holoweb.net
Tue Jul 31 15:21:28 PDT 2007


On Tue, 2007-07-31 at 17:25 -0400, Madison Kelly wrote:

>    But I would like to make this module portable so I want to be able to
> validate international phone numbers, too. Has anyone seen or done this?
> How might I go about checking telephone numbers from both NA and
> international?

In general, it can be pretty hard.  I had a friend whose
telephone number was Prickwillow 23, so you had to call the
international operator.

International phone numbers with direct dialing do have some
things you can check for usefully --
+country-code
followed usually by a code (often 0 or 1) that is to be dropped
when calling from outside the country
followed by digits, often with embedded punctuation.

If all you care about is that someone from either the same
or anothe country can dial the number, that's probably enough.

Andy pointed out Number::Phone, and that does have
Number::Phone::Normalize which might be useful.  It
looks like that package expects phone numbers to be just
digits and spaces (with an optional leading + sign), which
might or might not be what you need.  In practice you also
need to cope with "extension 3605" or "evenings only" too.

Liam


-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org



More information about the toronto-pm mailing list