通过正则匹配实现手机号的验证:
1 package demo; 2 3 import java.util.regex.Matcher; 4 import java.util.regex.Pattern; 5 6 public class PhoneValidate { 7 8 public static void main(String[] args) { 9 String value="17518900000"; 10 Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$"); 11 Matcher m = p.matcher(value); 12 System.out.println(m.matches());//boolean 13 } 14 }