# Validator Recognises null in 'notEmptyString'

**URL:** <https://discourse.cakephp.org/t/validator-recognises-null-in-notemptystring/10985>\
**Category:** Uncategorized\
**Created:** [February 27, 2023, 1:21pm UTC](https://discourse.cakephp.org/t/validator-recognises-null-in-notemptystring/10985 "2023-02-27T13:21:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yousuo](https://avatars.discourse-cdn.com/v4/letter/y/898d66/32.png) [@yousuo](https://discourse.cakephp.org/u/yousuo)\
**Post date:** [February 27, 2023, 1:21pm UTC](https://discourse.cakephp.org/t/validator-recognises-null-in-notemptystring/10985/1 "2023-02-27T13:21:01Z")

</div>

In the docs, it says a `null` key-presence is counted as valid. Is there a way to check for `null` values ? Maybe something like `notNullValue` option in the validator ?

`Key presence is checked by using array_key_exists() so that null values will count as present. You can set the mode using the second parameter:`

Problem example :

```auto
// in src/Modal/Table/xx.php

        $validator
            ->nonNegativeInteger('working_status')
            ->requirePresence('working_status', true )
            ->notBlank('working_status')
            ->notEmptyString('working_status');

```

After creating an entity (newEntity), there are errors reported by the entity. Once I set the field to `null`, the error disappears even though `notEmptyString` is in the validator.

```auto
// To simplify stuff. A simple array
// Error will be reported by entity ([hasErrors] => true)
$newEntity = $this->Users->newEntity([
  'working_status' => null
]);

// No error will be reported by entity after setting it to null ([hasErrors] => false)
$newEntity->working_status = null;

```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 27, 2023, 2:54pm UTC](https://discourse.cakephp.org/t/validator-recognises-null-in-notemptystring/10985/2 "2023-02-27T14:54:36Z")

</div>

I believe that validation is not checked at all when you do direct assignment to properties, only when you patch the entity.
