/** * 常用或自定义格式正则校验 * * @param string $value 源字符串 * @param string $checkName 校验类型或自定义正则表达式 * @return boolean */ function checkValid($value,$checkName,$minLength=0,$maxLength=NULL) { $regex = array( 'email' => '^[\w_+((-\w+)|(\.\w+))]*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$', 'phone' => '^([0-9]{3})|([0-9]{3}\-))?1(3)|(5)[0-9]{9}$', 'url' => '^(http|https|ftp):\/\/[A-Za-z0-9]+\.[A-Za-z0-9]*', 'currency' => '^[0-9]+(\.[0-9]+)?$', 'qq' => '^[1-9]\d{4,8}$', 'english' => '^[A-Za-z]+$', 'chinese' => '^[\xa1-\xff]+$', 'password' => '/^[a-zA-Z0-9]{6,20}$/i', 'name' => '^([\xa1-\xff]{1,8}|[A-Za-z0-9]{2,20})$', 'string' => “^[^`%&()=;:'\”/\\]*$”, 'int' => “^-?[1-9]+[0-9]*$”, 'float' => “^(-?[0-9]+)(\.[0-9]+)?$”, 'time' => “^(20|21|22|23|1[0-9]{1}|0?[0-9]{1})(:[0-5]?[0-9]{1})(:(60)|([0-5]?[0-9]{1}))?$”, 'card' => “^[0-9]{15}([0-9]{2}[A-Za-z0-9])?$”, 'post' => “^[0-9]{6}$”, ); if(isset($regex[strtolower($checkName)])) { $matchRegex = $regex[strtolower($checkName)]; }else { $matchRegex = $checkName; } if(eregi($matchRegex,$value) == false){ return false; } return chkStrLen($value,$minLength,$maxLength); }
]]>常用或自定义格式正则校验
本站未标注原创文章均为转载,如有侵权请告知!二宝博客 » 常用或自定义格式正则校验