respect-validation/docs/rules/Alnum.md
Henrique Moody 779c0c1503
Do not accept whitespace by default in "Alnum" rule
The "Alnum" rule is supposed to validate alphanumeric values, but
instead, it also validates any whitespace character as valid.

The rule also accepts a list of characters on its constructor, so it the
users intentionally want some specific characters to also be allowed it
is better than they also defined these characters on the rule's
constructor.

While refactoring the rule I could notice that "AbstractCtypeRule" is
just an overhead that does not add much to it, so instead of extending
it "Alnum" now extends "AbstractFilterRule" directly (which is the
parent of "AbstractCtypeRule").

And since we want all rules to follow our contribution guidelines, this
commit also make sure the "Alnum" rule is in accordance with that.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-04 00:05:24 +02:00

895 B

Alnum

  • Alnum()
  • Alnum(string $additionalChars)

Validates whether the input is alphanumeric or not.

Alphanumeric is a combination of alphabetic (a-z and A-Z) and numeric (0-9) characters.

v::alnum()->validate('foo 123'); // false
v::alnum(' ')->validate('foo 123'); // true
v::alnum()->validate('100%'); // false
v::alnum('%')->validate('100%'); // true

You can restrict case using the Lowercase and Uppercase rules.

v::alnum()->uppercase()->validate('example'); // false

Message template for this validator includes {{additionalChars}} as the string of extra chars passed as the parameter.

Changelog

Version Description
2.0.0 Removed support to whitespaces by default
0.3.9 Created

See also: