正则表达式
目前项目中用到的正则表达式
import java.util.regex.Pattern; public class RegexUtil { //默认数字 public static String NUM = "([0-9]*)|([0-9]*\\.[0-9]*)|-([0-9]*)|-([0-9]*\\.[0-9]*)"; //正数 public static String PLUS_NUM = "([0-9]*)|([0-9]*\\.[0-9]*)"; //数字总长度为15位,最多2位小数 public static String NUM_15_2 = "([1-9]\\d{0,12})|([1-9]\\d{0,12}\\.\\d{1,2})"; public static boolean match(String regex, Object input){ if (input == null) { return false; } return Pattern.matches(regex, input.toString()); } public static boolean isNumeric(Object str) { if (str == null) { return false; } Boolean isMatch = Pattern.matches(NUM, str.toString()); if (!isMatch) { return false; } if (str.toString().contains(",")) { return false; } return true; } }

浙公网安备 33010602011771号