1、車牌號(hào):
/**
*
* @description:驗(yàn)證車牌號(hào)
* @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、手機(jī)號(hào)碼:
/**
*
* @description:驗(yàn)證手機(jī)號(hào)碼
* @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;
}
手機(jī)號(hào)+固定電話:010-1111111,15516985859,0377-1111111
//java檢測(cè)是否為電話號(hào)碼(手機(jī)、固定電話驗(yàn)證)
String legalPhone = "";
String regExp ="^((13[0-9])|(15[^4,\D])|(18[0,5-9]))\d{8}|[0]{1}[0-9]{2,3}-[0-9]{7,8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(importPotentialBFOs[i].getLegalPhone());
if(m.find()){ //注意:m.find只能用一次,第二次調(diào)用后都為false
legalPhone = importPotentialBFOs[i].getLegalPhone();
uploadTmp.setLegalTelephone(legalPhone);
}else{
throw new BizException("聯(lián)系電話格式錯(cuò)誤!");
}
更多信息請(qǐng)查看IT技術(shù)專欄