- /**
- * 验证手机格式
- */
- public static boolean isMobileNO(String mobiles) {
- /*
- 移动: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卫通)
- 总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9
- */
- String telRegex = "[1][358]\\d{9}";//"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。
- if (TextUtils.isEmpty(mobiles)) return false;
- else return mobiles.matches(telRegex);
- }
//-------------------=========================--------------------------=============================--------------------
* */
public static boolean isPhoneNumberValid(String phoneNumber) {
boolean isValid = false;
String expression = "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-? \\d{7,8}-(\\d{1,4})$))";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches() ) {
isValid = true;
}
return isValid;
}
//===============================================================================================================
public
class
ClassPathResource {
public
static
boolean
isMobileNO(String mobiles) {
Pattern p = Pattern
.compile(
"^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$"
);
Matcher m = p.matcher(mobiles);
System.out.println(m.matches() +
"---"
);
return
m.matches();
}
public
static
void
main(String[] args)
throws
IOException {
System.out.println(ClassPathResource.isMobileNO(
"18977778989"
));
}
}
|