You are here: Re: US phone number validation « PHP Programming Language « IT news, forums, messages
Re: US phone number validation

Posted by Gordon Burditt on 09/28/21 11:44

>I'm still working on validating the phone numbers that are entered on a
>form but have come across a problem I don't understand how to fix. I can
>handle most instances when it's in regular US formats (555-555-5555 or
>(555) 555-5555 or 555 555 5555) but I'm having trouble when the entry is
>ten consecutive numbers with nothing else (5555555555). Not only does it
>not validate, but it shows as 2147483647 when I call the variable to
>check to see how it is set.

Telephone numbers are not integers. They are strings. In particular,
leading zeroes count. Don't treat them as numbers. Don't print
them using numeric formats. A 10-digit phone number may not fit in
a 32-bit integer. Although you won't find US phone numbers beginning
with zero, on international calls from the US it does matter whether
you dial a leading zero or not. Also, there's a difference between
817-555-0001 and 817-555-1.

US telephone numbers also occasionally have extensions, which makes
them longer than 10 digits.

>I know I could break the form up into three
>values as in <input name="phone[area]"> <input name="phone[code]"> and
><input name="phone[num]"> to eliminate that happening but I don't like
>the look of that and I know there's a better way that I haven't found.

My preference would be to STORE it as a digit string (varchar) and
display it in some standardized format I like. On input, it's probably
best to first strip out all the non-digits and then validate it.

>I tried googling for information on a preg_replace statement that could
>do what I need (check the phone number and add a space between the 3rd
>and 4th and the 6th and 7th digits if there isn't one there already) but
>I haven't been successful.

Gordon L. Burditt

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация