增加正则

This commit is contained in:
liuyingfang
2024-03-02 15:19:05 +08:00
parent 9f13d37960
commit 8f7acca8e6
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package me.zhengjie.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author lyf
*/
public class PhoneUtil {
public static boolean validator(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();
}
}
}