WindChat/windchat-common/src/main/java/com/windchat/common/utils/ValidatorPattern.java

119 lines
2.5 KiB
Java
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.windchat.common.utils;
import java.util.regex.Pattern;
public class ValidatorPattern {
/**
* 正则表达式:验证手机号
*/
public static final String REGEX_PHONDID = "^((13[0-9])|(15[^4,\\D])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";
/**
* 正则表达式:验证测试手机号
*/
public static final String TEST_REGEX_PHONDID = "^(20210000[0-9])\\d{2}$";
/**
* 正则表达式:验证邮箱
*/
public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
/**
* 正则表达式:验证汉字
*/
public static final String REGEX_CHINESE = "^[\u4e00-\u9fa5],{0,}$";
/**
* 正则表达式:验证身份证
*/
public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";
/**
* 正则表达式验证URL
*/
public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
/**
* 正则表达式验证IP地址
*/
public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
/**
* 校验手机号
*
* @param phoneId
* @return 校验通过返回true否则返回false
*/
public static boolean isPhoneId(String phoneId) {
if (phoneId == null) {
return false;
}
return Pattern.matches(REGEX_PHONDID, phoneId) || Pattern.matches(TEST_REGEX_PHONDID, phoneId);
}
/**
* 校验邮箱
*
* @param email
* @return 校验通过返回true否则返回false
*/
public static boolean isEmail(String email) {
if (email == null) {
return false;
}
return Pattern.matches(REGEX_EMAIL, email);
}
/**
* 校验汉字
*
* @param chinese
* @return 校验通过返回true否则返回false
*/
public static boolean isChinese(String chinese) {
if (chinese == null) {
return false;
}
return Pattern.matches(REGEX_CHINESE, chinese);
}
/**
* 校验身份证
*
* @param idCard
* @return 校验通过返回true否则返回false
*/
public static boolean isIDCard(String idCard) {
if (idCard == null) {
return false;
}
return Pattern.matches(REGEX_ID_CARD, idCard);
}
/**
* 校验URL
*
* @param url
* @return 校验通过返回true否则返回false
*/
public static boolean isUrl(String url) {
if (url == null) {
return false;
}
return Pattern.matches(REGEX_URL, url);
}
/**
* 校验IP地址
*
* @param ipAddr
* @return
*/
public static boolean isIPAddr(String ipAddr) {
if (ipAddr == null) {
return false;
}
return Pattern.matches(REGEX_IP_ADDR, ipAddr);
}
}