in reply to Re: Re: Another LostS Question - Phone Number Checks
in thread Another LostS Question - Phone Number Checks
This is a pet peeve of mine. There's more than one way to punctuate phone numbers, and no standardization among web sites:
Even if your instructions are perfectly clear about the expected format, the individual using it may be used to entering it in some other form. Handling multiple formats is much more user-friendly than issuing an error message.(xxx) yyy-zzzz +1 xxx yyy zzzz xxx-yyy-zzzz xxxyyyzzzz
A simple way to handle this is to accept any old cruft they type, remove everything that isn't a digit, and make sure you got ten digits. You can then format those digits for display or whatever:
$conphone =~ tr/0-9//dc; # remove non-digits if ($conphone =~ /^(\d{3})(\d{3})(\d{4})$/) { $conphone = $1 . '-' . $2 . '-' . $3; } else { print "Bad phone! No cookie!\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Another LostS Question - Phone Number Checks
by Brovnik (Hermit) on Aug 28, 2001 at 15:22 UTC |