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.
For USA state code validation, http://www.qwc.me/2013/12/us-states-list-static-php-array-with.html - this might help you.