Need to accept empty for number validation


Hi Team,
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?



Hi @phandgean,

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: ). It’s very simple.




Thank you and I made it work in the end with my own annotation.