SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Question 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.
    "Don't you just love it when you solve a programming bug only to create another."

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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:

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


  3. #3
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Thats a great idea, which I'd proberly would had thought of later. Still got logos in my head

    Definitely a better solution to the problem.
    "Don't you just love it when you solve a programming bug only to create another."

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dashes and parenthesis are very common.
    555-555-5555
    (555) 555-5555

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

  5. #5
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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).
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •