标签:
1、车牌号:
/**
*
* @description:验证车牌号
* @param carNum
* 豫A106EK
* @return 合法:true 不合法:false
*/
public static boolean validateCarNum(String carNum) {
boolean result = false;
String[] provence = new String[] { "京", "津", "冀", "晋", "辽", "吉", "黑", "沪", "苏", "浙", "皖", "闽", "赣", "鲁", "豫", "鄂", "湘", "粤", "桂", "琼", "渝",
"川", "黔", "滇", "藏", "陕", "甘", "青", "宁", "新", "港", "澳", "蒙" };
String reg = "[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}";
boolean firstChar = false;
if (carNum.length() > 0) {
firstChar = Arrays.asList(provence).contains(carNum.substring(0, 1));
}
try {
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(carNum);
if (m.matches() && firstChar) {
result = true;
} else {
result = false;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
2、手机号码:
/**
*
* @description:验证手机号码
* @param mobileNum 15516985859
* @return 合法:true 不合法:false
*/
public static boolean isMobileNum(String mobileNum) {
boolean result = false;
try {
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobileNum);
result = m.matches();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
参考:http://www.233.com/Java/zhuanye/20100924/102546666.html
标签:
原文地址:http://my.oschina.net/u/1389206/blog/401337