sometimes we may need to add validation on fields to read number value those transferred as String. if no value to transfer, empty might be received. then we hope to use digits annotation but can’t. is that possible to validate number but accept empty String?
As for the
@Digits annotation, it accepts null as a valid input but not the empty string. This is usually what we do in our built-in constraints.
I don’t think we’re gonna change that so what you have to do is to transform empty strings into null before the validation.
You can either do that in your business code or if you really want it, you can add your own constraint annotation (see our documentation here: https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-customconstraints ). It’s very simple.