[tpm] Regex to validate (international) phone numbers

Madison Kelly linux at alteeve.com
Tue Jul 31 14:25:30 PDT 2007


Hi all,

   To (hopefully) save some time I was hoping to pick TPM's collective
brain. I have a small module I use for validating various data types
(for user-input). One of the things I want to validate are telephone
numbers.

   I know I could strip off non-digit characters and then do something
like (not tested):

if ( $foo =~ /[1][\d{3}](\d{3})(\d{4})/) { print "$foo is valid\n" }

   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?

   I guess ultimately I can just write a series of simple regexes in
sequence but I am hoping for something more elegant/compact. :)

Thanks!

EDIT: Sent this the first time from my other email account. Sorry if 
this ends up being a dupe


More information about the toronto-pm mailing list