Java examples for java.util.regex:Match Phone Number
is Phone Number by regex
//package com.java2s; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String num = "java2s.com"; System.out.println(isPhoneNum(num)); }//from w ww . ja v a 2 s. c o m private static String mobPhoneNumRE = "^((13[0-9])|(17[0-9])|(15[^4])|(18[0,2-9]))\\d{8}$"; public static boolean isPhoneNum(String num) { return isModleStr(num, mobPhoneNumRE); } public static boolean isModleStr(String str, String regex) { if (str == null) { return false; } else { return Pattern.compile(regex).matcher(str).matches(); } } }