Java國際化號碼驗證方法,國內手機號正則表達式
中國電信號段 133、149、153、173、177、180、181、189、199 中國聯通號段 130、131、132、145、155、156、166、175、176、185、186 中國移動號段 134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198 其他號段 14號段以前為上網卡專屬號段,如中國聯通的是145,中國移動的是147等等。 虛擬運營商 電信:1700、1701、1702 移動:1703、1705、1706 聯通:1704、1707、1708、1709、171 衛星通信:1349
public static boolean isPhone(String phone) { String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"; if (phone.length() != 11) { return false; } else { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(phone); return m.matches(); } }
國際化號碼,先判斷區號為國內的+86再用國內的號碼正則表達式,國外的再逐個添加規則
public static boolean isPhone(String countrycode,String phone) { if (isNullOrEmpty(phone)) { return false; } //china phone if("+86".equals(countrycode)) { String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"; if (phone.length() != 11) { return false; } else { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(phone); return m.matches(); } } return true; }