验证手机号主要求是我们要知道有那些号码段了,下面我们来看看几条Java正则表达式判断手机号的例子,希望文章能够帮助到各位朋友。
故先要整清楚现在已经开放了多少个号码段,国家号码段分配如下:
移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
联通:130、131、132、152、155、156、185、186
电信:133、153、180、189、(1349卫通)
那么现在就可以正则匹配测试了,
import ;
import ;
import ;
public class ClassPathResource {
public static boolean isMobileNO(String mobiles){
Pattern p = ("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = (mobiles);
(() "---");
return ();
}
public static void main(String[] args) throws IOException {
(("12016155153"));
}
}
第二种方法:
import ;
import ;
String value="手机号";
String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";
Pattern p = (regExp);
Matcher m = (value);
return ();//boolean
第三种方法:
String check = "^([a-z0-9A-Z] [-|.]?) [a-z0-9A-Z]@
([a-z0-9A-Z] (-[a-z0-9A-Z] )?.) [a-zA-Z]{2,}$";
Pattern regex = (check);
Matcher matcher = (email);
flag = ();
}catch(Exception e){
flag = false;
}
return flag;
}
/**
* 验证手机号码
* @param mobiles
* @return [0-9]{5,9}
*/
public static boolean isMobileNO(String mobiles){
boolean flag = false;
try{
Pattern p = ("^((13[0-9])|(15[^4,D])|(18[0,5-9]))d{8}$");
Matcher m = (mobiles);
flag = ();
}catch(Exception e){
flag = false;
}
return flag;
}
public static boolean isNum(String number){
boolean flag = false;
try{
Pattern p = ("^[0-9]{5}$");
Matcher m = (number);
flag = ();
}catch(Exception e){
flag = false;
}
return flag;
}
}