# Need to accept empty for number validation

**URL:** <https://discourse.hibernate.org/t/need-to-accept-empty-for-number-validation/85>\
**Category:** Bean Validation (JSR 380)\
**Created:** [January 18, 2018, 3:04am UTC](https://discourse.hibernate.org/t/need-to-accept-empty-for-number-validation/85 "2018-01-18T03:04:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phandgean](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@phandgean](https://discourse.hibernate.org/u/phandgean)\
**Post date:** [January 18, 2018, 3:04am UTC](https://discourse.hibernate.org/t/need-to-accept-empty-for-number-validation/85/1 "2018-01-18T03:04:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [January 19, 2018, 2:46pm UTC](https://discourse.hibernate.org/t/need-to-accept-empty-for-number-validation/85/2 "2018-01-19T14:46:30Z")

</div>

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: [https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html\_single/#validator-customconstraints](https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-customconstraints) ). It’s very simple.

HTH

---

<div class="post-metadata">

**Author:** ![phandgean](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@phandgean](https://discourse.hibernate.org/u/phandgean)\
**Post date:** [February 27, 2019, 7:38am UTC](https://discourse.hibernate.org/t/need-to-accept-empty-for-number-validation/85/3 "2019-02-27T07:38:24Z")

</div>

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