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"; }

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.