package com.cxqy.business.security.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 手机号校验
*/
public final class MobileVerification {
private MobileVerification() {
// Suppresses default constructor, ensuring non-instantiability.
}
/**
* 判断是否是手机号
*
* @param mobileNumber 传入的手机号码
* @return 返回boolean类型
*/
public static boolean mobileVerification(String mobileNumber) {
//正则表达式验证手机规则
Pattern p = Pattern.compile("^[1][0-9]{10}$");
Matcher m = p.matcher(mobileNumber);
return m.matches();
}
/**
* 检验电话号码是否符合规则
*
* @param phone
* @return
*/
public static Boolean checkPhone(String phone) {
Pattern p = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$");
Matcher m = p.matcher(phone);
return m.find();
}
}
if (mobile != null && (mobile.trim().equals("") || !MobileVerification.checkPhone(mobile))) {
return Resp.buildFail(HttpStatus.BAD_REQUEST, "手机号不存在");
}