USA phone numbers

Hi guys,

The other day a business person tried to become a registered member on my website who is based in the US. He entered the phone number but was thrown out with a message saying it’s not numeric.

Now, I know why it through the message, because he had entered the number with the minus sign inbetween the numbers. Do the US always place the minus sign inbetween the phone numbers? Have you had problems due to this?

In the mean time I’ll place a message requesting not to place anything else except for numbers.

It seems to be pretty common in advertising and websites’ contact details. It’s also common in Peru, for example. Rather than asking people to do something different, you’d probably be advised to do a simple string replace:

if (is_numeric(trim(str_replace('-', '', $num))) {
  // it's a number

Thats a great idea, which I’d proberly would had thought of later. Still got logos in my head :headbang:

Definitely a better solution to the problem. :slight_smile:

Dashes and parenthesis are very common.
(555) 555-5555

There’s really a lot of variation though. Don’t be strict here.

You could just
preg_replace(‘/[^0-9]/’, $number)
and check if strlen() === 10.

Be careful with the +NN too. I always write +44 (UK international) instead of 0 (UK domestic).