There is a telephonenumber format that looks about like (I hope I remember correctly):
$telephoneNumber =~ /^\+(\d\d)\-(\d+)(:?\-(\d+))+$;/
where $1 +\d\d stands for the countrycode, $2 the areacode (=citycode), $3 the number, and maybe $4 for a sharing number (don't know the english word).
e.g: +49-69-44885599
or: +49-69-123-12345
(whereas the + is replaced by a local far distance call numbers, e.g. 00 in Germany, and I think 1 in the USA).
But I'm not quite sure if this format is really a standard or not (will try to find the definition again; was something with ISDN-Number in X400 or the like).
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print" | [reply] [Watch: Dir/Any] [d/l] |
I would start by defining your problem more precisely. Which of the following would you consider a phone number that you want to match?
555-1212
310-555-1212
1-310-555-1212
(310) 555-1212
310.555.1212
+1 (310) 555-1212
310-555-1212, extension 1234
011 (46) 12-345678
1-800-MATTRES (leave off the last "S" for savings ;-)
etc. etc. It'll be much easier to devise a regex after you've figured out what it is you're actually looking for. | [reply] [Watch: Dir/Any] |
To follow up on that, I would come up with the best possible function I could come up with to normalize phone numbers, and start a test script that will test a list of phone numbers. As you feel the need to match weirder formats, edit your function to normalize them, run the test script to see if it still works for all cases and then add it to the application you are doing.
Also if the normalize_phone_number function is placed in a module you can use the Test.pm module to build your test script.
I think I would start by treating any non alphanumeric character as a separator, and substitute one or more separators by my normalized separator. then start from the right of the string, first separator after the 6 character is local number, next group is regional, and ... darn, forgot extensions. You're on your own :)
Tiago
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] [d/l] |