Validates only if value is not null
.
Optional(
Validator $validator,
);
Validator::optional(
Validator::type('int')->greaterThanEqualTo(18)
)->validate(null); // true
Validator::optional(
Validator::type('int')->greaterThanEqualTo(18)
)->validate(20); // true
Validator::optional(
Validator::type('int')->greaterThanEqualTo(18)
)->validate(16); // false
type: Validator
required
Validator that will validate the input value only when it is not null
.
1.0.0
Created