laminas / laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

Home Page:https://docs.laminas.dev/laminas-validator/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NotEmpty to allow null but dont allow no value

cbichis opened this issue · comments

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

Is needed to allow null values as valid values but dont allow no value provided as a valid value. Currently as far as I know there is no such possibility.

By example it would be useful to run a Validator if the value provided is null...

This is highly specific functionality, and I would create a custom validator in this case, using the Callback validator:

$validator = new Callback(function (mixed $value): bool {
    if (null === $value) {
        return true;
    }
   return ! empty($value);
});

Thanks @weierophinney for your suggestion. Is something easily doable so I agree with your conclusion.

Actually this is not good. In case we have null value the validators are not firing...

@cbichis
Please describe your problem in the forum with a code example. Then we can find a suitable solution for the callback validator.