package com.clg.base.dptAddress.utils;
import org.springframework.stereotype.Component;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
public class PhoneUtiles {
public boolean VerifyPhone(String mobile) {
String regex = "^((13[0-9])|(14[0,1,4-9])|(15[0-3,5-9])|(16[2,5,6,7])|(17[0-8])|(18[0-9])|(19[0-3,5-9]))\d{8}$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(mobile);
return m.matches();
}
}
测试:
public static void main(String[] args) {
PhoneUtiles phoneUtiles = new PhoneUtiles();
boolean b1 = phoneUtiles.VerifyPhone("17623054011");
boolean b2 = phoneUtiles.VerifyPhone("12312312311");
System.out.println(b1);
System.out.println(b2);
}
运行结果:
true
false



