PHP应用
PHP各种验证代码
```php <?php /** * 验证邮箱 */ public static function email($str) { if (empty($str)) return true; $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i"; if (strpos($str, '@') !== false && strpos($str, '.') !== false) { if (preg_match($chars, $str)) { return true; } else { return false; } } else { return false; } } /** * 验证手机号码 */ public static function mobile($str) { if (empty($str)) { return true; } return preg_match('#^13[\d]{9}$|14^[0-9]\d{8}|^15[0-9]\d{8}$|^18[0-9]\d{8}$#', $str); } /** * 验证固定电话 */ public static function tel($str) { if (empty($str)) { return true; } return preg_match('/^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/', trim($str)); } /** * 验证qq号码 */ public static function qq($str) { if (empty($str)) { return true; } return preg_match('/^[1-9]\d{4,12}$/', trim($str)); } /** * 验证邮政编码 */ public static function zipCode($str) { if (empty($str)) { return true; } return preg_match('/^[1-9]\d{5}$/', trim($str)); } /** * 验证ip */ public static function ip($str) { if (empty($str)) return true; if (!preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $str)) { return false; } $ip_array = explode('.', $str); //真实的ip地址每个数字不能大于255(0-255) return ( $ip_array[0] <= 255 && $ip_array[1] <= 255 && $ip_array[2] <= 255 && $ip_array[3] <= 255 ) ? true : false; } /** * 验证身份证(中国) */ public static function idCard($str) { $str = trim($str); if (empty($str)) return true; if (preg_match("/^([0-9]{15}|[0-9]{17}[0-9a-z])$/i", $str)) return true; else return false; } /** * 验证网址 */ public static function url($str) { if (empty($str)) return true; return preg_match('#(http|https|ftp|ftps)://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?#i', $str) ? true : false; } /** * 检测是否为英文或英文数字的组合 * * @return unknown */ public static function isEnglist($param) { if (!eregi("^[A-Z0-9]{1,26}$", $param)) { return false; } else { return true; } } ```
顶部
收展
底部
[TOC]
目录
PHP中常用的header头部定义
PHP压缩包下载
PHP文件下载
PHP常用加密函数总结
URL请求参数加解密
PHP文件操作功能函数
PHP判断远程文件是否存在
PHP生成GUID的函数
PHP通用请求函数CURL封装
PHP获取访问者IP地址
PHP图片操作
PHP实现发红包程序
PHP各种验证代码
PHP防XSS 防SQL注入的代码
PHP遍历目录下的全部文件
PHP获取中文字符拼音首字母
PHP判断输入数据是否合法常用的类
相关推荐
PHP底层
PHP面向对象
PHP工具类
PHP编程经验
PHP框架