"Richard Kurth" <[EMAIL PROTECTED]> wrote:
> I am using this script to validate for phone numbers and it work just
> perfect for US phone numbers. But it rejects some European and
> Australian numbers what do I need to do to make it validate all phone
> numbers
>
> if (($WPHONE_NO) || ($wphone_no)) {
>    $wphone_no = trim($wphone_no);
>    if ($WPHONE_NO)
>       $phone_no = trim($WPHONE_NO);
>    if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $wphone_no))
{
>       print_error("your <b>phone number</b> is invalid");
>    }
> }

It would be helpful if you post a list of the range of phone numbers you are
encountering that you are having a problem with.  Or I can get you started
by saying that I think you're regular expression is saying "beginning with
anything, then exactly 3 numbers, then anything, then exactly 3 numbers,
then anything, then ending in exactly 4 numbers".  Changing a {3} to {3,4}
would mean "match 3-4 occurences of what's to the left".  Hopefully that
will get you started, if you post some other numbers you want to pass
validation we can be of more assistance.  regex are very powerful and I
recommend you add them to your training.  That said, people enter #s in many
different formats and sometimes it's necessary to enter a # like
"011-817-972-1086 x103" or "817-972-1086, 1, 3, 12" if you're dealing with
business numbers with extensions or automated systems that have to be
traversed.  So you may be better off not validating the phone #.  YMMV.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/

Reply via email to