import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @ClassName: VerifyUtil
* @Description:参数校验工具类
* @author John Hawkings
* @date 2016年12月9日 下午3:45:50
*/
public class VerifyUtil {
/**
* 检查手机号是否合法
*
* @param phone
* @return
*/
public static boolean verifyPhone(String phone) {
String regExp = "^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(phone);
return m.matches();
}
/**
* 检查密码是否合法
*
* @param phone
* @return
*/
public static boolean verifyPwd(String password){
String regExp = "^[a-zA-Z0-9]{6,22}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(password);
return m.matches();
}
/**
* 检查昵称是否合法
*
* @param phone
* @return
*/
public static boolean verifyNickName(String nick){
if(nick.length()>0&&nick.length()<=12){
return true;
}else{
return false;
}
}
/**
* 检查邮箱是否合法
*
* @param phone
* @return
*/
public static boolean verifyEmail(String email){
String regExp = "^(www\\.)?\\w+@\\w+(\\.\\w+)+$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(email);
return m.matches();
}
/**
* 检验微信是否合法
* @param weixin
* @return
*/
public static boolean verifyWeixin(String weixin){
String regExp = "^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}+$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(weixin);
return m.matches();
}
/**
* 检验qq是否合法
* @param qq
* @return
*/
public static boolean verifyQq(String qq){
String regExp = "[1-9][0-9]{4,12}";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(qq);
return m.matches();
}
}
常用手机号,邮箱,用户名 ,昵称校验工具类
最新推荐文章于 2024-08-01 18:45:00 发布