SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex validation: PHP

    Could someone help me with verifying phone numbers like (415) 765-6890. It consists of 3 numerals in round brackets, then a space, then 3 numerals again, then a minus sign, then 4 numerals.

    Please help me.
    `~@#\^%&*/\.<.\/-|+|_!:;..=?>
    PHP, SEO | anshul shrivastava | mediasworks.org | FB

  2. #2
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    /^\(\d{3}\) \d{3}\-\d{4}$/

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is NOT working:
    Code:
    $pattern = "/^\(\d{3}\) \d{3}\-\d{4}$/";
    $subject = "(415) 956-2003";
    if( ereg($pattern, $subject) )
    	echo "CORRECT";
    else
    	echo "WRONG";
    .
    `~@#\^%&*/\.<.\/-|+|_!:;..=?>
    PHP, SEO | anshul shrivastava | mediasworks.org | FB

  4. #4
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Who told you to use ereg?

    PHP Code:
    $pattern "/^\(\d{3}\) \d{3}\-\d{4}$/";
    $subject "(415) 956-2003";
    if (
    preg_match($pattern$subject))
        echo 
    "CORRECT";
    else
        echo 
    "WRONG"

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fine. You're regex expert!
    `~@#\^%&*/\.<.\/-|+|_!:;..=?>
    PHP, SEO | anshul shrivastava | mediasworks.org | FB


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
  •