Skip to content

Instantly share code, notes, and snippets.

@lotsofbytes
Last active October 6, 2018 19:27
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/99f1dc323843a8a3e39c7d0420a99179 to your computer and use it in GitHub Desktop.
Save lotsofbytes/99f1dc323843a8a3e39c7d0420a99179 to your computer and use it in GitHub Desktop.
[バリデーション:email] #laravel #L55 #validation

バリデーション:email

入力値がEメールアドレスの文字列かを判定。

laravel 5.5

gistの画面

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

$ git clone git@gist.github.com:99f1dc323843a8a3e39c7d0420a99179.git tests/Unit/Validations/Email
<?php
namespace Tests\Unit\Validations\Email;
use Tests\TestCase;
use Validator;
class EmailTest extends TestCase
{
/**
* @test
* @dataProvider provider_email
*/
public function email($input, $expected)
{
$v = Validator::make(
$input,
['field' => 'required|email']
);
$this->assertEquals($expected, $v->passes());
}
public function provider_email()
{
return [
[['field' => 'example.com'], false],
[['field' => 'test@example.com'], true],
[['field' => 't.est@example.com'], true],
[['field' => 't..est@example.com'], false],
[['field' => 'test.@example.com'], false],
[['field' => 'test@docomo.ne.jp'], true],
[['field' => 't.est@docomo.ne.jp'], true],
[['field' => 't..est@docomo.ne.jp'], false], // 不正ではない
[['field' => 'test.@docomo.ne.jp'], false], // 不正ではない
[['field' => 'test@dezweb.ne.jp'], true],
[['field' => 't.est@ezweb.ne.jp'], true],
[['field' => 't..est@ezweb.ne.jp'], false], // 不正ではない
[['field' => 'test.@ezweb.ne.jp'], false], // 不正ではない
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment