public class DecimalValidator implements ConstraintValidator<IsDecimal, Map<String,Object>> {
String pointPrefix = "(\\-|\\+){0,1}\\d*\\.\\d+";
String pointSuffix = "(\\-|\\+){0,1}\\d+\\.";
String pointPrefixWithoutPoint = "\\-{0,1}\\d+";
@Override
public void initialize(IsDecimal constraintAnnotation) {
}
public boolean isValid(Map<String,Object> map, ConstraintValidatorContext arg1) {
String value = (String)map.get(Constants.KEY);
if (StringUtils.isEmpty(value) && (boolean)(map.get(Constants.REQUIRED)))
return false;
return value.matches(pointPrefix) || value.matches(pointSuffix) || value.matches(pointPrefixWithoutPoint);
}
}