Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Validator.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class Validator extends \Magento\Framework\Validator\AbstractValidator
12 {
16  protected $countryFactory;
17 
21  public function __construct(
22  \Magento\Directory\Model\CountryFactory $countryFactory
23  ) {
24  $this->countryFactory = $countryFactory;
25  }
26 
38  public function isValid($value)
39  {
40  $messages = [];
41  $email = $value->getEmail();
42  if (!empty($email) && !\Zend_Validate::is($email, \Magento\Framework\Validator\EmailAddress::class)) {
43  $messages['invalid_email_format'] = 'Invalid email format';
44  }
45 
46  $countryId = $value->getCountryId();
47  if (!empty($countryId)) {
48  $country = $this->countryFactory->create();
49  $country->load($countryId);
50  if (!$country->getId()) {
51  $messages['invalid_country_code'] = 'Invalid country code';
52  }
53  }
54 
55  $this->_addMessages($messages);
56 
57  return empty($messages);
58  }
59 }
$email
Definition: details.phtml:13
__construct(\Magento\Directory\Model\CountryFactory $countryFactory)
Definition: Validator.php:21
$value
Definition: gender.phtml:16
static is($value, $classBaseName, array $args=array(), $namespaces=array())
Definition: Validate.php:195