package com.qianwen.smartman.common.utils;
|
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
public class ValidatorUtils {
|
public static final String REGEX_USERNAME = "^[a-zA-Z0-9]{6,20}$";
|
public static final String REGEX_PASSWORD = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,15}$";
|
public static final String REGEX_MOBILE = "^((13[0-9])|(14[0-9])|(15[^4,\\D])|(16[0-9])|(18[0-9])|(17[0-9])|(19[0-9]))\\d{8}$";
|
public static final String REGEX_EMAIL = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
|
public static final String REGEX_CHINESE = "^[一-龥],{0,}$";
|
public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";
|
public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
|
public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
|
public static final String REGEX_NUMBER = "^[-\\+]?[\\d]*$";
|
|
public static boolean isUsername(String username) {
|
return Pattern.matches(REGEX_USERNAME, username);
|
}
|
|
public static boolean isPassword(String password) {
|
return Pattern.matches(REGEX_PASSWORD, password);
|
}
|
|
public static boolean isMobile(String mobile) {
|
return Pattern.matches(REGEX_MOBILE, mobile);
|
}
|
|
public static boolean isEmail(String email) {
|
return Pattern.matches(REGEX_EMAIL, email);
|
}
|
|
public static boolean isChinese(String chinese) {
|
return Pattern.matches(REGEX_CHINESE, chinese);
|
}
|
|
public static boolean isIDCard(String idCard) {
|
if (idCard.toUpperCase().matches("(^\\d{15}$)|(^\\d{17}([0-9]|X)$)")) {
|
return true;
|
}
|
return false;
|
}
|
|
public static boolean isUrl(String url) {
|
return Pattern.matches(REGEX_URL, url);
|
}
|
|
public static boolean isIPAddr(String ipAddr) {
|
return Pattern.matches(REGEX_IP_ADDR, ipAddr);
|
}
|
|
public static boolean isCarCode(String carCode) {
|
if (carCode.toUpperCase().matches("[一-龥]{1}[A-Z]{1}[A-Z_0-9]{5}")) {
|
return true;
|
}
|
return false;
|
}
|
|
public static boolean isCarNo(String CarNum) {
|
if (CarNum != null && !"".equals(CarNum)) {
|
String s1 = CarNum.substring(0, 1);
|
if ("京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼甲乙丙己庚辛壬寅辰戍午未申".contains(s1)) {
|
String s2 = CarNum.substring(1, CarNum.length());
|
if (!s2.contains("I") && !s2.contains("i") && !s2.contains("O") && !s2.contains("o") && !CarNum.matches("^[一-龥]{1}[A-Z]{1}[A-Z_0-9]{5}$")) {
|
return true;
|
}
|
return false;
|
}
|
return false;
|
}
|
return false;
|
}
|
|
public static boolean isLegalName(String name) {
|
if (name.contains("·") || name.contains("•")) {
|
if (name.matches("^[\\u4e00-\\u9fa5]+[·•][\\u4e00-\\u9fa5]+$")) {
|
return true;
|
}
|
return false;
|
} else if (name.matches("^[\\u4e00-\\u9fa5]+$")) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
public static boolean stringFilter(String str) {
|
Pattern p = Pattern.compile("[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、? ]");
|
Matcher m = p.matcher(str);
|
return m.find();
|
}
|
|
public static boolean isNumber(String number) {
|
return Pattern.matches(REGEX_NUMBER, number);
|
}
|
|
public static boolean checkContextLength(String context) {
|
int length = context.length();
|
return length > 32;
|
}
|
|
public static boolean checkContextLength(String context, int contextLength) {
|
int length = context.length();
|
return length > contextLength;
|
}
|
|
public static void main(String[] args) {
|
System.out.println(isUsername("fdsdfsdj"));
|
System.out.println(isChinese("fdsdfsdj"));
|
System.out.println(isEmail("123@qq.com"));
|
System.out.println(isMobile("13914265646"));
|
}
|
}
|