前端之家收集整理的这篇文章主要介绍了
正则法则验证邮箱和手机号码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
publicclassCheckMobileAndEmail{
/****验证邮箱地址是否正确**@paramemail**@return*/
publicstaticbooleancheckEmail(Stringemail){
booleanflag=false;
try{
Stringcheck="^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";Patternregex=Pattern.compile(check);
Matchermatcher=regex.matcher(email);
flag=matcher.matches();
}catch(Exceptione){
flag=false;
}
returnflag;
}
/****验证手机号码**@parammobiles**@return[0-9]{5,9}*/
publicstaticbooleanisMobileNO(Stringmobiles){
booleanflag=false;
try{
Patternp=Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcherm=p.matcher(mobiles);
flag=m.matches();
}catch(Exceptione){
flag=false;
}
returnflag;
}
publicstaticbooleanisNum(Stringnumber){
booleanflag=false;
try{
Patternp=Pattern.compile("^[0-9]{5}$");
Matcherm=p.matcher(number);
flag=m.matches();
}catch(Exceptione){
flag=false;
}
returnflag;
}}
原文链接:https://www.f2er.com/regex/361012.html