代码
package cn.ucmed.merger.util;
import org.apache.commons.lang.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Ye Zongxiu
* @ClassName ELUtil
* @Description
* @date 2017年09月15日 10:41
*/
public class ELUtil {
private static final Pattern PATTERN_PHONE = Pattern
.compile("^1\\d{10}$");
private static final Pattern PATTERN_NAME = Pattern
.compile("^([\u4E00-\u9FA5]{2,7})|([a-zA-Z]{3,10})$");
private static final Pattern PATTERN_IDCARD = Pattern
.compile("^\\d{15}(\\d{2}[0-9xX])?$");
private static final Pattern PATTERN_POST = Pattern
.compile("^[1-9]\\d{5}(?!\\d)$");
private static final Pattern BANK_CARD = Pattern
.compile("^[0-9]{16,19}$");
private static final Pattern IS_CHINESE = Pattern
.compile("^[\u4E00-\u9FA5]$");
private static final Pattern IS_ENGLISH = Pattern
.compile("^[a-zA-Z]$");
private static final Pattern IS_NUMBER = Pattern
.compile("^[0-9]$");
/**
* 判断是否是手机号码.
*
* @param mobile 手机号码字符串.
* @return true 判断<strong>可能</strong>是手机号码;false 判断肯定不是手机号码。
*/
public static boolean isMobileNO(String mobile) {
if (StringUtils.isBlank(mobile)) {
return false;
}
Matcher m = PATTERN_PHONE.matcher(mobile);
return m.matches();
}
/**
* 匹配真实姓名(2~7个中文或者3~10个英文)只能是中文或英文,不能为数字或其他字符,汉字和字母不能同时出现
*/
public static boolean isName(String name) {
Matcher m = PATTERN_NAME.matcher(name);
return m.matches();
}
/**
* 身份证15位的和18位的,而且后面还可以跟(17位加)大写的X
*/
public static boolean isCard(String card) {
if (card == null) {
return false;
}
Matcher m = PATTERN_IDCARD.matcher(card);
return m.matches();
}
/**
* 邮编
*/
public static boolean isPost(String post) {
Matcher m = PATTERN_POST.matcher(post);
return m.matches();
}
/**
* 性别必须1男2女
*/
public static boolean isSex(String sex) {
if (StringUtils.isBlank(sex)) {
return false;
}
boolean boo = false;
if ("1".equals(sex) || "2".equals(sex)) {
boo = true;
}
return boo;
}
/**
* 是否为银行卡
*/
public static boolean isBankCard(String bankCard) {
Matcher m = BANK_CARD.matcher(bankCard);
return m.matches();
}
/**
* 是否为中文
*/
public static boolean isChinese(String name) {
Matcher m = IS_CHINESE.matcher(name);
return m.matches();
}
/**
* 是否为英文
*/
public static boolean isEnglish(String name) {
Matcher m = IS_ENGLISH.matcher(name);
return m.matches();
}
/**
* 是否为数字
*/
public static boolean isNumber(String name) {
Matcher m = IS_NUMBER.matcher(name);
return m.matches();
}
public static void main(String[] args) {
System.out.println(isCard("123456789123456789"));
}
}