-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement better email validation support
These changes allow for multiple email validators to be added when checking for valid emails. This is a continuation of the previous PR: laravel/framework#26503 Basically this allows for two things: - Make use of multiple email validators provided by the egulias/email-validator package - Use the previous (and much requested) filter_var validation By default nothing's breaking because it'll still use the RFC validator to when no validators are passed to the email validation rule. But you can opt to include different ones or multiple ones: 'email' => 'email:rfc,dns' Or opt for the pre-5.8 behavior: 'email' => 'email:filter' Which will use `filter_var` to validate the email address. This should give people a little more flexibility when doing email validation.
- Loading branch information
1 parent
02af31d
commit 0c0f628
Showing
2 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Illuminate\Validation\Concerns; | ||
|
||
use Egulias\EmailValidator\EmailLexer; | ||
use Egulias\EmailValidator\Exception\InvalidEmail; | ||
use Egulias\EmailValidator\Validation\EmailValidation; | ||
use Egulias\EmailValidator\Warning\Warning; | ||
|
||
class FilterEmailValidation implements EmailValidation | ||
{ | ||
/** | ||
* Returns true if the given email is valid. | ||
* | ||
* @param string $email The email you want to validate. | ||
* @param EmailLexer $emailLexer The email lexer. | ||
* | ||
* @return bool | ||
*/ | ||
public function isValid($email, EmailLexer $emailLexer) | ||
{ | ||
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; | ||
} | ||
|
||
/** | ||
* Returns the validation error. | ||
* | ||
* @return InvalidEmail|null | ||
*/ | ||
public function getError() | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the validation warnings. | ||
* | ||
* @return Warning[] | ||
*/ | ||
public function getWarnings() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters