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