forked from egulias/EmailValidator
/
GMailValidation.php
45 lines (35 loc) · 1.22 KB
/
GMailValidation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Validates if the e-mail is a valid gmail account.
* @author Jerônimo Fagundes da Silva <jeronimo.fs@protonmail.com>
*/
namespace Egulias\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\InvalidGMailUser;
use Egulias\EmailValidator\Exception\NoGMailDomain;
class GMailValidation extends RFCValidation
{
const GMAIL_MIN_USER_LENGTH = 6;
const GMAIL_MAX_USER_LENGTH = 30;
public function isValid($email, EmailLexer $emailLexer){
if (!parent::isValid($email, $emailLexer)) {
return false;
}
list($user, $domain) = explode('@', $email);
if (strtolower($domain) != 'gmail.com') {
$this->error = new NoGMailDomain();
return false;
}
if (!preg_match("/^([a-z]|[A-Z]|[0-9]|\.|\+)+$/", $user)) {
$this->error = new InvalidGMailUser();
return false;
}
$userExplodePlus = explode('+', $user);
$len = strlen($userExplodePlus[0]);
if ($len < static::GMAIL_MIN_USER_LENGTH || $len > static::GMAIL_MAX_USER_LENGTH) {
$this->error = new InvalidGmailUser();
return false;
}
return true;
}
}