mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
The intent of the "Alpha" rule is to validate alphabetic values. However, it also considers any whitespace character (by default). That causes some confusion, and unless you check its code or tests, you would never expect that behavior. Because of that confusion, I decided to make "Alpha" to not consider whitespace characters as valid, and since in the constructor of this rule it's possible to add extra characters to the validation it makes sense to let the user decide whether they want whitespaces, tabs, new lines, etc. or not. This rule, as the same as "Alnum" previously, extends "AbstractCtypeRule" pretty much to only make it easier to consider any whitespaces as valid, therefore I saw no reason to keep extending it. Now "Alpha" extends the "AbstractFilterRule" which is the parent of "AbstractCtypeRule". I also took the opportunity to apply our contribution guidelines to "Alpha" since we want to apply that to all the rules. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
34 lines
762 B
PHP
34 lines
762 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use function ctype_alpha;
|
|
|
|
/**
|
|
* Validates whether the input contains only alphabetic characters.
|
|
*
|
|
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
* @author Nick Lombard <github@jigsoft.co.za>
|
|
*/
|
|
final class Alpha extends AbstractFilterRule
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function validateClean($input)
|
|
{
|
|
return ctype_alpha($input);
|
|
}
|
|
}
|