手機號碼 正則匹配工具類

2021-08-21 23:33:50 字數 751 閱讀 3579

public class phoneutils   

/**

* 大陸手機號碼11位數,匹配格式:前三位固定格式+後8位任意數

* 此方法中前三位格式有:

* 13+任意數

* 15+除4的任意數

* 18+除1和4的任意數

* 17+除9的任意數

* 14 + 5 7 9

* 166

*/19 + 8 9

public static boolean ischinaphonelegal(string str) throws patternsyntaxexception $";

pattern p = pattern.compile(regexp);

matcher m = p.matcher(str);

return m.matches();

} /**

* 香港手機號碼8位數,5|6|8|9開頭+7位任意數

*/

public static boolean ishkphonelegal(string str)throws patternsyntaxexception $";

pattern p = pattern.compile(regexp);

matcher m = p.matcher(str);

return m.matches();

} }

匹配手機號碼

1 static void main string args 222 string pattern 1 23 regex rx new regex pattern 24 string input 18817889736 23487 3241247531432 432432145 1589556581...

工具類 手機號碼校驗

方便自己下次使用。public class checkphone d d d 中國電信號碼格式驗證 手機段 133,153,180,181,189,177,1700,173 private static final string china telecom pattern 1 33 53 7 37 ...

驗證手機號碼工具類

驗證手機號碼 author dujiayu time 2020年4月25日11 12 57 public class numberutil 用於匹配固定 號碼 private final static string regex fixedphone 010 02 d 0 3 9 d d 用於獲取固定...