respect-validation/docs/validators/Alpha.md
Henrique Moody d2198dfd01
Replace isValid() calls with assert()
There's more value on showing how `assert()` displays the validation
messages than simply showing if `isValid()` returns `true` or `false`.

However, that increases the chances of having outdated documentation, so
I created a doc linter that updates the Markdown files with the
correct message.
2026-01-13 23:37:06 -07:00

2.3 KiB

Alpha

  • Alpha()
  • Alpha(string ...$additionalChars)

Validates whether the input contains only alphabetic characters. This is similar to Alnum, but it does not allow numbers.

v::alpha()->assert('some name');
// → "some name" must contain only letters (a-z)

v::alpha(' ')->assert('some name');
// Validation passes successfully

v::alpha()->assert('Cedric-Fabian');
// → "Cedric-Fabian" must contain only letters (a-z)

v::alpha('-')->assert('Cedric-Fabian');
// Validation passes successfully

v::alpha('-', '\'')->assert('\'s-Gravenhage');
// Validation passes successfully

You can restrict case using the Lowercase and Uppercase validators.

v::alpha()->uppercase()->assert('example');
// → "example" must contain only uppercase letters

Templates

Alpha::TEMPLATE_STANDARD

Mode Template
default {{subject}} must contain only letters (a-z)
inverted {{subject}} must not contain letters (a-z)

Alpha::TEMPLATE_EXTRA

Mode Template
default {{subject}} must contain only letters (a-z) and {{additionalChars}}
inverted {{subject}} must not contain letters (a-z) or {{additionalChars}}

Template placeholders

Placeholder Description
additionalChars Additional characters that are considered valid.
subject The validated input or the custom validator name (if specified).

Categorization

  • Strings

Changelog

Version Description
2.0.0 Removed support to whitespaces by default
0.3.9 Created

See also: