* 页面作用:常用表单验证类* 作 者:phper* 建立时间:2011-4-11*/class validate{public static function isEmail($str){ return is_string($str)&&preg_match('/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$/',$str);}public static function isUrl($str){ return is_string($str)&&preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^\"\"])*$/",$str);}public static function isPhone($str,$type){$preg_array_pho=array('cn'=>'/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/','tw'=>'');if(in_array($type,array_keys($pre_array_pho))){return preg_match($pre_array_pho[$type],$str);}else{die($type.'-phone number is undefined');}}public static function isText($str,$type,$min_lenth=1,$max_lenth=''){$preg_array_text=array('ch'=>"/^([\x81-\xfe][\x40-\xfe]){".$min_lenth.",".$max_lenth."}$/",'num'=>"/^[0-9]{".$min_lenth.",".$max_lenth."}$/i",);if(in_array($type,array_keys($preg_array_text))){return is_string($preg_array_text)&&preg_match($preg_array_text[$type],$str);}else{die($type.'-text is undefined');}}public static function isIp($ip){ return preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" . "(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $ip);} public static function isDate($var){ return preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/",$var);} public static function isColor($var){ return preg_match("/^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$/",$var);} public static function isUserName($var){ return preg_match("/^[a-zA-Z0-9_\.\-]{3,16}$/",$var);} public static function isPic($var){ return preg_match("/^[a-zA-Z0-9\-\.]+\.(jpg|jpeg|gif|png)$/",$var);}}?>复制代码 09-19 01:03