# Don't validate if field if null

**URL:** <https://discourse.hibernate.org/t/dont-validate-if-field-if-null/2192>\
**Category:** Hibernate Validator\
**Created:** [February 1, 2019, 5:31pm UTC](https://discourse.hibernate.org/t/dont-validate-if-field-if-null/2192 "2019-02-01T17:31:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbax1982](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kbax1982](https://discourse.hibernate.org/u/kbax1982)\
**Post date:** [February 1, 2019, 5:31pm UTC](https://discourse.hibernate.org/t/dont-validate-if-field-if-null/2192/1 "2019-02-01T17:31:46Z")

</div>

Hi

I am using hibernate validation to validate a brazillian number for companies, called CNPJ

```auto
	@CNPJ
	@Column(nullable = true, length = 18, unique = true)
	private String cnpj;

```

But in my form this field is not required.

But and I try to save a register with CNPJ field null, I got a NotValidException.

How do I not validate if this field is null ?

---

<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:** [February 1, 2019, 6:06pm UTC](https://discourse.hibernate.org/t/dont-validate-if-field-if-null/2192/2 "2019-02-01T18:06:22Z")

</div>

Hi,

Are you sure the exception is coming from Hibernate Validator? Because we do accept null values: [https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/hv/br/CNPJValidator.java#L53](https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/constraintvalidators/hv/br/CNPJValidator.java#L53) .

---

<div class="post-metadata">

**Author:** ![kbax1982](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@kbax1982](https://discourse.hibernate.org/u/kbax1982)\
**Post date:** [February 4, 2019, 12:58pm UTC](https://discourse.hibernate.org/t/dont-validate-if-field-if-null/2192/3 "2019-02-04T12:58:12Z")

</div>

I think so…

And out front-end is sending CNPJ field with “”, and not “null”. I think this is the problem…

Now I am trying to send “null” instead “”
