入力値が数字や記号文字を含まない文字列かを判定。半角英字の判定ではないことに注意。つまり日本語の文字列はどれもOK
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:a17165670783b4f22d88551f5e2ee098.git tests/Unit/Validations/Alpha
入力値が数字や記号文字を含まない文字列かを判定。半角英字の判定ではないことに注意。つまり日本語の文字列はどれもOK
以下の実行で、ダウンロードできます
$ git clone git@gist.github.com:a17165670783b4f22d88551f5e2ee098.git tests/Unit/Validations/Alpha
<?php | |
namespace Tests\Unit\Validations\Alpha; | |
use Tests\TestCase; | |
use Validator; | |
class AlphaTest extends TestCase | |
{ | |
/** | |
* @test | |
* @dataProvider provider_alpha | |
*/ | |
public function alpha($input, $expected) | |
{ | |
$v = Validator::make( | |
$input, | |
['field' => 'required|alpha'] | |
); | |
$this->assertEquals($expected, $v->passes()); | |
} | |
public function provider_alpha() | |
{ | |
return [ | |
[['field' => 'abcd'], true], | |
[['field' => 'ABCD'], true], | |
[['field' => 'ログイン'], true], | |
[['field' => 'ろぐいん'], true], | |
[['field' => '漢字'], true], | |
[['field' => 'ab cd'], false], | |
[['field' => '-'], false], | |
[['field' => '_'], false], | |
[['field' => '0'], false], | |
[['field' => '1'], false], | |
]; | |
} | |
} |