in reply to Re: Another LostS Question - Phone Number Checks
in thread Another LostS Question - Phone Number Checks

Thank You :)

Here is what I did :)
if ( $conphone =~ /(\d{3})-(\d{3})-(\d{4})/ ) { print "Phone: $conphone<br />\n"; } else { print "BAD PHONE!!!! BAD PHONE!!!!<br />\n"; }
It seems to work :) Do you see anythign wrong with that??

Thanks
Billy S.

Replies are listed 'Best First'.
Re: Re: Re: Another LostS Question - Phone Number Checks
by kjherron (Pilgrim) on Aug 24, 2001 at 00:24 UTC
    It's not very user-friendly. You're forcing them to enter their phone number in a particular format, when you could just as easily format the number for them.

    This is a pet peeve of mine. There's more than one way to punctuate phone numbers, and no standardization among web sites:

    (xxx) yyy-zzzz +1 xxx yyy zzzz xxx-yyy-zzzz xxxyyyzzzz
    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.

    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"; }
      <soapbox> I agree about the "pet peeve". Often, I try to register on a US site and it won't accept my UK phone number.
      Even UK systems screw up since we often have number changes and the websites often don't change quickly enough.
      Suggestion (adding to comments by [id://kjherron]) :

      Allow any format, strip down to digits, and check for a reasonable number of digits to allow for international dialing codes, etc. then leave it at that.

      If you want real validation, you'll need to check the dialing codes for each potential country to see if they are OK, and KEEP THE DATABASE UP-TO-DATE.
      </soapbox>
      --
      Brovnik