正则表达式
今天给大家带来手机和电话号码的正则表达式,废话少说,直接上代码。
手机号码匹配:
/**
* 验证手机号码
*
* 移动号码段:139、138、137、136、135、134、150、151、152、157、158、159、182、183、187、188、147、182
* 联通号码段:130、131、132、136、185、186、145
* 电信号码段:133、153、180、189、177
*
* @param cellphone
* @return
*/
public static boolean checkCellphone(String cellphone) {
String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,1,2,5-9])|(177))\\d{8}$";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(cellphone);
return matcher.matches();
}
固定电话号码匹配:
/**
* 验证固话号码
* @param telephone
* @return
*/
public static boolean checkTelephone(String telephone) {
String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(telephone);
return matcher.matches();
}
如果还有其他的最新号码段,烦请大家提出来。
本文分享了Java中用于匹配手机号码和固定电话号码的正则表达式,提供了相关代码示例,并邀请读者分享最新的号码段。

4029

被折叠的 条评论
为什么被折叠?



