respect-validation/docs/validators/Format.md
Henrique Moody 6abf3a548c
Remove Masked validator in favor of Formatted
The Masked validator was a proxy for what the new Formatted validator
already does, so it is being removed to reduce redundancy. All tests and
documentation have been updated accordingly.

Assisted-by: OpenCode (ollama-cloud/glm-4.7)
2026-02-06 20:44:26 +01:00

2.1 KiB

Format

  • Format(Formatter $formatter)

Validates whether an input is already formatted as the result of applying a provided Respect\StringFormatter Formatter to it. You can build formatters using Respect\StringFormatter\FormatterBuilder (commonly aliased as f).

v::format(f::pattern('00-00'))->assert('42-33');
// Validation passes successfully

v::format(f::pattern('00-00'))->assert('42.33');
// → "42.33" must be formatted as "42-33"

v::format(f::mask('1-@'))->assert('alganet@gmail.com');
// → "alganet@gmail.com" must be formatted as "*******@gmail.com"

v::not(v::format(f::pattern('00-00')))->assert('42-33');
// → "42-33" must not be formatted as "42-33"

v::named('Vanity plate', v::format(f::pattern('AAA-0000')))->assert('DAD8008');
// → Vanity plate must be formatted as "DAD-8008"

This validator is useful when you need to assert that data is already in a desired presentation (for example, ensuring that a masking tool was already applied or that stored data follows a required display format).

Templates

Format::TEMPLATE_STANDARD

Mode Template
default {{subject}} must be formatted as {{formatted}}
inverted {{subject}} must not be formatted as {{formatted}}

Template placeholders

Placeholder Description
formatted The value resulting from applying the provided formatter to the input
subject The validated input or the custom validator name (if specified).

Categorization

  • Display
  • Strings

Changelog

Version Description
3.0.0 Created

See Also