Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotsofbytes/89e1823eb985fa7c7d6d07ba17de4e6c to your computer and use it in GitHub Desktop.
Save lotsofbytes/89e1823eb985fa7c7d6d07ba17de4e6c to your computer and use it in GitHub Desktop.
[バリデーション:regex] #laravel #L55 #validation

バリデーション:regex

入力値が、指定の正規表現のパターンにマッチすることを判定。

laravel 5.5

gistの画面

以下の実行で、ダウンロードできます

$ git clone git@gist.github.com:89e1823eb985fa7c7d6d07ba17de4e6c.git tests/Unit/Validations/Regex
<?php
namespace Tests\Unit\Validations\Regex;
use Tests\TestCase;
use Validator;
class RegexTest extends TestCase
{
/**
* @test
* @dataProvider provider_regex
*/
public function regex_test($input, $expected)
{
$v = Validator::make(
$input,
['field' => 'required|regex:/^([a-z]+)$/']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_regex()
{
return [
[['field' => 'abcd'], true],
[['field' => 'ABCD'], false],
[['field' => ' abcd'], false],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment