• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

这个PHP验证类如何使用?

php 搞代码 3年前 (2022-01-25) 15次浏览 已收录 0个评论
文章目录[隐藏]

比如我写好的POST提交例子,验证邮箱和值是否未空?

<code>include("check.php");  $check = new VerifyAction();  if(?){   echo '提交成功!';  }else{    echo '填写不对 重填写'; }   <br>   <br>      </code>

验证类 check.php

<code><?php/** * 验证类 * * @lastmodify        2014-5-16 * @author           jy625 */class VerifyAction{    /**     * 是否为空值     */      public static function isEmpty($str){        $str = trim($str);            return !empty($str) ? true : false;    }    /**     * 数字验证     * param:$flag : int是否是整数,float是否是浮点型     */          public static function isNum($str,$flag = 'float'){        if(!self::isEmpty($str)) return false;        if(strtolower($flag) == 'int'){            return ((string)(int)$str === (string)$str) ? true : false;        }else{            return ((string)(float)$str === (string)$str) ? true : false;        }    }     /**     * 名称匹配,如用户名,目录名等     * @param:string $str 要匹配的字符串     * @param:$chinese 是否支持中文,默认支持,如果是匹配文件名,建议关闭此项(false)     * @param:$charset 编码(默认utf-8,支持gb2312)     */      public static function isName($str,$chinese = true,$charset = 'utf-8'){        if(!self::isEmpty($str)) return false;        if($chinese){            $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-]+$/" : "/^[x{4e00}-x{9fa5}A-Za-z0-9_]+$/u";        }else{            $match = '/^[A-za-z0-9_-]+$/';        }        return preg_match($match,$str) ? true : false;    }    /**     * 邮箱验证     */          public static function isEmail($str){        if(!self::isEmpty($str)) return false;        return preg_match("/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i",$str) ? true : f<div>本文#来源gaodai.ma#com搞##代!^码7网</div><pre>搞代gaodaima码

alse; } //手机号码验证 public static function isMobile($str){ $exp = “/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/”; if(preg_match($exp,$str)){ return true; }else{ return false; } } /** * URL验证,纯网址格式,不支持IP验证 */ public static function isUrl($str){ if(!self::isEmpty($str)) return false; return preg_match(‘#(http|https|ftp|ftps)://([w-]+.)+[w-]+(/[w-./?%&=]*)?#i’,$str) ? true : false; } /** * 验证中文 * @param:string $str 要匹配的字符串 * @param:$charset 编码(默认utf-8,支持gb2312) */ public static function isChinese($str,$charset = ‘utf-8’){ if(!self::isEmpty($str)) return false; $match = (strtolower($charset) == ‘gb2312’) ? “/^[“.chr(0xa1).”-“.chr(0xff).”]+$/” : “/^[x{4e00}-x{9fa5}]+$/u”; return preg_match($match,$str) ? true : false; } /** * UTF-8验证 */ public static function isUtf8($str){ if(!self::isEmpty($str)) return false; return (preg_match(“/^([“.chr(228).”-“.chr(233).”]{1}[“.chr(128).”-“.chr(191).”]{1}[“.chr(128).”-“.chr(191).”]{1}){1}/”,$word) == true || preg_match(“/([“.chr(228).”-“.chr(233).”]{1}[“.chr(128).”-“.chr(191).”]{1}[“.chr(128).”-“.chr(191).”]{1}){1}$/”,$word) == true || preg_match(“/([“.chr(228).”-“.chr(233).”]{1}[“.chr(128).”-“.chr(191).”]{1}[“.chr(128).”-“.chr(191).”]{1}){2,}/”,$word) == true) ? true : false; } /** * 验证长度 * @param: string $str * @param: int $type(方式,默认min <= $str = $min) ? true : false; break; case 2: //只匹配最大值 return ($max >= $len) ? true : false; break; default: //min <= $str <= max return (($min <= $len) && ($len = 1000 && $timeArr[0] = 0 && $dateArr[1] = 0 && $dateArr[2] = 0 && $timeArr[0] = 0 && $timeArr[1] = 0 && $timeArr[2] <= 59)) return true; else return false; } return false; } }

回复内容:


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:这个PHP验证类如何使用?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址