正则表达式匹配移动、联通、电信号码

编程入门 行业动态 更新时间:2024-10-26 02:29:58

正则表达式匹配移动、联通、电信<a href=https://www.elefans.com/category/jswz/34/1761714.html style=号码"/>

正则表达式匹配移动、联通、电信号码

/*** 验证是否为电信手机号* @author liubin**/
public class CheckPhoneNumber {/** 国家号码段分配如下:移动: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*///匹配移动手机号码//public static String str1 = "^1(3[4-9]|5[01789]|8[78])\\d{8}$";//匹配移动手机号码//public static String str2 = "^1(3[0-2]|5[256]|8[56])\\d{8}$";//匹配电信号码public static String str = "^(18[09]|1[35]3)\\d{8}$";/*** 验证单个号码* @param number* @return*/public static boolean isPhoneNumber(String number){ Pattern p = Patternpile(str);  Matcher m = p.matcher(number); return m.matches(); } /*** 验证批量号码* @param list* @return*/public static boolean isPhoneNumberAll(String[] list){ Pattern p = Patternpile(str);for (String string : list) {if(string.length()!=11) return false;Matcher m = p.matcher(string); if(!m.matches()){return false;}}return true; }
}



更多推荐

正则表达式匹配移动、联通、电信号码

本文发布于:2024-02-12 08:21:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1686942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:号码   电信   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!