<?PHP/** * [email protected] Zouhao * Some verification methods*/ /** * is the mobile number * * @param string $phone phone number * @return Boolean*/ functionIs_phone ($phone) { if(strlen($phone)! = 11 | | !Preg_match('/^1[3|4|5|8][0-9]\d{4,8}$/',$phone )) { return false; } Else { return true; } } /** * Verify that strings are numbers, letters, Chinese, and underscores * @param string $username * @return bool*/ functionIs_check_string ($str){ if(Preg_match('/^[\x{4e00}-\x{9fa5}\w_]+$/u ',$str)){ return true; }Else{ return false; } } /** * is a valid email * @param sting $email * @return Boolean*/ functionIs_email ($email){ if(Filter_var ($email,filter_validate_email)) { return true; } Else { return false; } }/** * e-mail Verification can also use this method * This method for reference Ecshop*/ functionIs_email ($user _email){ $chars= "/^" ([a-z0-9+_]|\\-|\\.) [Email protected] (([a-z0-9_]|\\-) +\\.) +[a-z]{2,6}\$/i "; if(Strpos($user _email, ' @ ')!==false&&Strpos($user _email, ‘.‘) !==false) { if(Preg_match($chars,$user _email)) { return true; } Else { return false; } } Else { return false; }} /** * is a valid URL * @param string $url * @return Boolean*/ functionIs_url ($url){ if(Filter_var ($url,Filter_validate_url)) { return true; } Else { return false; } } /** * is a valid IP address * @param string $ip * @return Boolean*/ functionIS_IP ($ip){ if(Ip2long($ip)) { return true; } Else { return false; } } /** * is an integer * @param int $number * @return Boolean*/ functionIs_number ($number){ if(Preg_match('/^[-\+]?\d+$/',$number)){ return true; }Else{ return false; } } /** * is a positive integer * @param int $number * @return Boolean*/ functionIs_positive_number ($number){ if(Ctype_digit($number)){ return true; }Else{ return false; } } /** * is a decimal * @param float $number * @return Boolean*/ functionIs_decimal ($number){ if(Preg_match('/^[-\+]?\d+ (\.\d+)? $/',$number)){ return true; }Else{ return false; } } /** * is a positive decimal number * @param float $number * @return Boolean*/ functionIs_positive_decimal ($number){ if(Preg_match('/^\d+ (\.\d+)? $/',$number)){ return true; }Else{ return false; } } /** * is English * @param string $str * @return Boolean*/ functionIs_english ($str){ if(Ctype_alpha($str)) return true; Else return false; } /** * is Chinese * @param string $str * @return Boolean*/ functionIs_chinese ($str){ if(Preg_match('/^[\x{4e00}-\x{9fa5}]+$/u ',$str)) return true; Else return false; } /** * To determine if it is a picture * @param string $file picture file path * @return Boolean*/ functionIs_image ($file){ if(file_exists($file) &&getimagesize($file===false)){ return false; }Else{ return true; } } /** * is a valid ID (supports 15-bit and 18-bit) * @param string $card * @return Boolean*/ functionIs_card ($card){ if(Preg_match('/^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$/',$card)||Preg_match('/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{4}$/',$card)) return true; Else return false; } /** * Verify that the date format is correct * @param string $date * @param string $format * @return Boolean*/ functionIs_date ($date,$format= ' y-m-d '){ $t=date_parse_from_format ($format,$date); if(Empty($t[' Errors '])){ return true; }Else{ return false; } } ?>
Some validation functions have just been collected.
PHP validation functions (including Email,url, dates, and so on)