//手機號碼
private static final String MOBILE = "^(13[0123456789][0-9]{8}|15[012356789][0-9]{8}|18[012356789][0-9]{8}|147[0-9]{8}|170[0-9]{8}|177[0-9]{8})$";
//浮點數保留兩位小數
private static final String DECIMALREG = "^[+]?(([1-9]\\d*[.]?)|(0.))(\\d{0,2})?$";
//正整數不能爲0
private static final String POSITIVEINTEGER = "^[1-9]\\d*$";
//正整數包括0
private static final String POSITIVEINTEGER1 = "^[1-9]\\d*|0$";.net
/**
* 驗證手機號碼
* @param mobile
* @return boolean
* @throws Exception
*/
public static boolean isMobile(String mobile) throws Exception{
if(StringUtil.isEmpty(mobile))
throw new Exception("電話號碼不能爲空");
Pattern pattern = Pattern.compile(MOBILE);
Matcher matcher = pattern.matcher(mobile.trim());
return matcher.matches();
}get
/**
* 驗證數字
* 浮點數保留兩位小數
* @param numberStr
* @return boolean
*/
public static boolean validateNumber(String numberStr){
if(StringUtil.isEmpty(numberStr)) return false;
Pattern pattern = Pattern.compile(DECIMALREG);
Matcher matcher = pattern.matcher(numberStr.trim());
return matcher.matches();
}
/**
* 驗證數字
* 正整數不能爲0
* @param numberStr
* @return boolean
*/
public static boolean validatePositiveInteger(String numberStr){
if(StringUtil.isEmpty(numberStr)) return false;
Pattern pattern = Pattern.compile(POSITIVEINTEGER);
Matcher matcher = pattern.matcher(numberStr.trim());
return matcher.matches();
}
/**
* 驗證數字
* 正整數包括0
* @param numberStr
* @return boolean
*/
public static boolean validatePositiveInteger1(String numberStr){
if(StringUtil.isEmpty(numberStr)) return false;
Pattern pattern = Pattern.compile(POSITIVEINTEGER1);
Matcher matcher = pattern.matcher(numberStr.trim());
return matcher.matches();
}it