java常用正則和參數驗證工具類
工具類
package cn.demo.tools;
import cn.demo.RegexConstants;
import java.util.regex.*;
/**
* Created by sc on 2018/3/5.
* 參數校驗工具類
*/
public class DataValidator {
public static boolean check(String str, String regex) {
boolean flag ;
try {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
flag = matcher.matches();
} catch (Exception e) {
flag = false;
}
return flag;
}
/**
* 是否是郵件
*
* @param value
*/
public static boolean isEmail(String value) {
return check(value, RegexConstants.EMAIL);
}
/**
* 是否是QQ號碼
*
* @param value
*/
public static boolean isQq(String value) {
return check(value, RegexConstants.QQ);
}
/**
* 是否爲純數字
* @return
*/
public static boolean isStringNum(String