版权声明:默先森||[email protected] https://blog.csdn.net/Error_Q/article/details/90174774
吾生也有涯,而知也无涯~欢迎优化补充、指正!
(直接调用方法稍加修改即可使用,或者单独粘贴相应验证!)
* 手机号码验证包括最新16、19字段的手机号
*本文是在tp5下进行编译与调试的
/*
*验证用户名,手机号,邮箱,QQ,微信号
*(用户名:字母、数字或下划线组成大于等于2位的字符串)
*/
public function verify($username='',$mobile='',$email='',$qq='',$wx='')
{
//用户名验证
if(!empty($username)&&!preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/',$username))
return ['code'=>'201','msg'=>'用户名格式不正确!'];
//验证电话
if(!empty($mobile)&&!preg_match("/^1[3456789]\d{9}$/ims",$mobile))
return ['code'=>'201','msg'=>'请输入正确的手机号码!'];
//验证邮箱
if(!empty($email)&&!preg_match("/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims",$email))
return ['code'=>'201','msg'=>'请输入正确的邮箱!'];
//验证qq
if(!empty($qq)&&!preg_match("/^\d{5,10}$/isu",$qq))
return ['code'=>'201','msg'=>'请输入正确的QQ号码!'];
//验证微信号
if(!empty($wx)&&!preg_match("/^[_a-zA-Z0-9]{5,19}+$/isu",$wx))
return ['code'=>'201','msg'=>'请输入正确的微信号!'];
return '非空该方法没进行验证哦!';
}