Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Latest commit

 

History

History
56 lines (37 loc) · 1.45 KB

03-rules_not-blank.md

File metadata and controls

56 lines (37 loc) · 1.45 KB

NotBlank

Validates that a value is not equal to an empty string, empty array, false or null.

Check the Blank rule for the opposite validation.

NotBlank(
    ?callable $normalizer = null,
    ?string $message = null
);

Basic Usage

Bellow are the only cases where the rule will fail by default, everything else is considered valid (you may want to check the normalizer option for a different behaviour):

Validator::notBlank()->validate(''); // false
Validator::notBlank()->validate([]); // false
Validator::notBlank()->validate(false); // false
Validator::notBlank()->validate(null); // false

Options

normalizer

type: ?callable default: null

Allows to define a callable that will be applied to the value before checking if it is valid.

For example, use trim, or pass your own function, to not allow a string with whitespaces only:

Validator::notBlank(normalizer: 'trim')->validate(' '); // false
Validator::notBlank(normalizer: fn($value) => trim($value))->validate(' '); // false

message

type: ?string default: The {{ name }} value should not be blank.

Message that will be shown if the value is blank.

The following parameters are available:

Parameter Description
{{ value }} The current invalid value
{{ name }} Name of the invalid value

Changelog

  • 0.1.0 Created