@Test public void validateDecimalTest(){ Assert.assertThat(true, Is.is(ValidateUtils.validateDecimal("1.10", 2))); Assert.assertThat(true, Is.is(ValidateUtils.validateDecimal("0.1", 2))); Assert.assertThat(false, Is.is(ValidateUtils.validateDecimal("-0.1", 2))); Assert.assertThat(false, Is.is(ValidateUtils.validateDecimal("1.10", 1))); }
public static boolean validateDecimal(String decimal, int maxDecimalLength) { if (maxDecimalLength < 1) { return false; } return decimal.matches("^(([1-9]\\d+)|(\\d))(\\.\\d{1," + maxDecimalLength + "})?$"); }
ValidateUtils { public static boolean validateDecimal(String decimal, int maxDecimalLength) { if (maxDecimalLength < 1) { return false; } return decimal.matches("^(([1-9]\\d+)|(\\d))(\\.\\d{1," + maxDecimalLength + "})?$"); } }
ValidateUtils { public static boolean validateDecimal(String decimal, int maxDecimalLength) { if (maxDecimalLength < 1) { return false; } return decimal.matches("^(([1-9]\\d+)|(\\d))(\\.\\d{1," + maxDecimalLength + "})?$"); }  }
ValidateUtils { public static boolean validateDecimal(String decimal, int maxDecimalLength) { if (maxDecimalLength < 1) { return false; } return decimal.matches("^(([1-9]\\d+)|(\\d))(\\.\\d{1," + maxDecimalLength + "})?$"); }  static boolean validateDecimal(String decimal, int maxDecimalLength); static boolean validateDiscount(String discount); }
ValidateUtils { public static boolean validateDecimal(String decimal, int maxDecimalLength) { if (maxDecimalLength < 1) { return false; } return decimal.matches("^(([1-9]\\d+)|(\\d))(\\.\\d{1," + maxDecimalLength + "})?$"); }  static boolean validateDecimal(String decimal, int maxDecimalLength); static boolean validateDiscount(String discount);  }