boolean matches(String regex)
/**
*
* @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;
}
/**
*
* @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;
}
//java检测是否为电话号码(手机、固定电话验证)
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只能用一次,第二次调用后都为false
legalPhone = importPotentialBFOs[i].getLegalPhone();
uploadTmp.setLegalTelephone(legalPhone);
}else{
throw new BizException("联系电话格式错误!");
}
String[] arrs=new String[]{"a","1.123","-1.23","0","+111"};
String regex="-?\\d+\\.?\\d*";
Pattern p = Pattern.compile(regex);
for (int i = 0; i < arrs.length; i++) {
Matcher m = p.matcher(arrs[i]);
System.out.println(arrs[i]+":"+m.matches());
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有