0

I want to validate US phone number, US state code and US zip code using PHP for it I wrote following functions but they are not working properly.

/** check phone number validation**/
  function phone_no($str) { 
    return (bool)eregi( "^([-\(\)\+, 0-9])+$", $str );
  }
/** check zip code validation**/
function integer($str) {
    return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
  }
/** check state code validation **/

    function alpha_num_symbol($str) {
        return ( ! preg_match("/^([a-z0-9\+_\.*-\/'& ])+$/i", $str)) ? FALSE : TRUE;
    }

I'm passing the value from input field of form using variable $str. Can someone please help me in correcting my code so that I can properly validate US phone number, US zip code and US state code. If anyone have any idea to make this thing workable please help me. Thanks in advance.

4

1 回答 1

1
// For USA zip code validation
function validateUSAZip($zip_code) {
    return preg_match(“/^([0-9]{5})(-[0-9]{4})?$/i”,$zip_code);
}

对于美国州代码验证,http://www.qwc.me/2013/12/us-states-list-static-php-array-with.html - 这可能会对您有所帮助。

于 2014-06-04T05:47:27.527 回答