Pattern matching Phone, Email

    Date: 07/24/05 (PHP Community)    Keywords: no keywords

    This is driving me nuts.


    I am trying to validate a form, phone numbers, and the phone number has to be "xxx xxx-xxxx"

    Here is my pattern "^([0-9]{3})( [0-9]{3})([0-9]{4})$"


    my code:


    function VALIDATE_USPHONE($phonenumber)
    {
    if ((preg_match("^([0-9]{3})( [0-9]{3})([0-9]{4})$", $phonenumber)) == TRUE ) {
    return $phonenumber;
    } else {
    return false;
    }
    }

    VALIDATE_USPHONE(trim($_POST[Home_Phone]));
    if ($phonenumber) {
    $account['HOME_PHONE'] = trim($_POST[Home_Phone]);
    }




    Also, if any one want to suggest a pattern for email, I'd take that too.

    Source: http://www.livejournal.com/community/php/324652.html

« RegEx Help - Updated || Distributed development tool? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home