| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /**
- * 参数检查类
- *
- * 收集常用的检查参数的函数集中于此类
- *
- * @createtime 2018/03/01
- * @author 空竹
- * @copyright 芝麻开发(http://www.zhimawork.com)
- */
- class ParamCheck {
-
- /**
- * is_mobile() 手机号格式是否正确
- *
- */
- static public function is_mobile($mobile){
- if(preg_match("/^1[0-9]{10}$/", $mobile)){
- return true;
- }else{
- return false;
- }
- }
- /**
- * is_email()邮箱格式是否正确
- * 2016/7/27更新正则表达式
- */
- static public function is_email($email)
- {
- if(preg_match("/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,}$/", $email)){
- return true;
- }else{
- return false;
- }
- }
- /**
- * 检查时间格式
- * 形如:yyyy-mm-dd hh:ii:ss
- *
- */
- static public function is_datetime($timestr){
-
- $patten = "/^([0-9]{4})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])\s+(0?[0-9]|1[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9]):(0?[0-9]|[1-5][0-9])$/";
-
- if(preg_match($patten, $timestr, $parts)){
- if(checkdate($parts[2], $parts[3], $parts[1]))
- return true;
- else
- return false;
- }else{
- return false;
- }
-
- }
- /**
- * 检查日期格式
- * 形如:yyyy-mm-dd
- *
- */
- static public function is_date($datestr){
-
- $patten = "/^([0-9]{4})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$/";
-
- if(preg_match($patten, $datestr, $parts)){
- if(checkdate($parts[2], $parts[3], $parts[1]))
- return true;
- else
- return false;
- }else{
- return false;
- }
-
- }
- /**
- * 检查弱密码
- * @return 弱密码--true 非弱密码--false
- */
- static public function is_weakPwd($pwd){
- if(strlen($pwd)<6) return true;
- $weakPwd = array(
- '000000','0000000',
- '111111','666666','888888','999999','88888888','11111111',
- 'aaaaaa',
- '123456789','1234567890','0123456789','12345678',
- '123456','654321','abcdef',
- 'abc123','123123','321321','112233','abcabc',
- 'aaa111','a1b2c3',
- 'qwerty','qweasd',
- 'password','p@ssword','passwd','passw0rd',
- 'iloveyou','5201314',
- 'admin1234','admin888','admin123'
- );
- if(in_array($pwd, $weakPwd))
- return true;
- else
- return false;
- }
- /**
- * 检查是否为数字(包括整数、小数和负数)
- * @param string
- * @return boolean
- */
- static public function is_number($val){
- return (bool)preg_match('/^\-?([0-9]{1}|[1-9]+[0-9]*)(\.[0-9]+)?$/', $val);
- }
- /**
- * 检查是否为正整数,多用于检查ID合法性
- * @param string
- * @return boolean
- */
- static public function is_ID($val){
- return (bool)preg_match('/^([1-9]+[0-9]*)$/', $val);
- }
- /**
- * 检查是否为身份证号
- * @param string
- * @return boolean
- */
- static public function is_idcard($val){
- return (bool)preg_match('/(^\d{15}$)|(^\d{17}(\d|X)$)/', $val);
- }
- /**
- * 检查是否为邮政编码
- * @param string
- * @return boolean
- */
- static public function is_postcode($val){
- return (bool)preg_match('/^(\d{6})$/', $val);
- }
- }
- ?>
|