{@link javax.validation.constraints.Digits} constraint validatorimplementation for a {@link String}.
String
35363738394041
@Digits(integer = 4, fraction = 2) private double defaultField; @Override protected DigitsValidatorForString createValidator() { return new DigitsValidatorForString(); }
49505152535455565758596061
val = new BigDecimal("99.1234"); Assert.assertTrue(validator.isValid(val, null)); } public void testValidateString() { DigitsValidatorForString validator = new DigitsValidatorForString(); validator.setFractional(4); validator.setIntegral(2); String val = "100.12345"; Assert.assertFalse(validator.isValid(val, null)); val = "99.1234"; Assert.assertTrue(validator.isValid(val, null)); }
69707172737475767778798081
val = new Long("99"); Assert.assertTrue(validator.isValid(val, null)); } public void testValidateString2() { DigitsValidatorForString validator = new DigitsValidatorForString(); validator.setFractional(0); validator.setIntegral(2); String val = "99.5"; Assert.assertFalse(validator.isValid(val, null)); val = "99"; Assert.assertTrue(validator.isValid(val, null)); }