<?php ????class preg ???{ ???????public function telP($tel) ???????{ ???????????$preg = ‘/^1[34578]\d{9}$/‘; ???????????$res = preg_match($preg, $tel); ???????????if(!$res){ ???????????????myNotice(‘手机号码格式不正确!‘); ???????????} ???????} ???????public function strP($str) ???????{ ???????????$preg = ‘/[\<\>\‘\"]/‘; ???????????$res = preg_match($preg, $str); ???????????if($res){ ???????????????myNotice(‘不能含有引号或括号‘); ???????????} ???????} ???????public function numP($num,$name=‘‘) ???????{ ???????????$preg = ‘/^\d{1,8}$/‘; ???????????$res = preg_match($preg, $num); ???????????if(!$res){ ???????????????myNotice($name.‘只能是8位纯数字‘); ???????????} ???????????$this->strP($num); ???????} ???????public function priceP($pri) ???????{ ???????????$preg = ‘/^\d{1,8}\.?\d{0,2}$/‘; ???????????$res = preg_match($preg, $pri); ???????????if(!$res){ ???????????????myNotice(‘单价格式不正确‘); ???????????} ???????????$this->strP($num); ???????} ???????public function pwdP($pwd) ???????{ ???????????$preg = ‘/^\w{3,12}$/‘; ???????????$res = preg_match($preg, $pwd); ???????????if(!$res){ ???????????????myNotice(‘密码只能是3到12位的数字,字母,下划线‘); ???????????} ???????} ???}
以上是验证类的源码
调用
使用
PHP验证类
原文地址:https://www.cnblogs.com/JiangDakang/p/9353971.html