eZ\Publish\Core\FieldType\Validator\EmailAddressValidator::validate PHP Method

validate() public method

Will return true when all constraints are matched. If one or more constraints fail, the method will return false. When a check against a constraint has failed, an entry will be added to the $errors array.
public validate ( Value $value ) : boolean
$value eZ\Publish\Core\FieldType\Value
return boolean
    public function validate(BaseValue $value)
    {
        $pattern = '/^((\\"[^\\"\\f\\n\\r\\t\\v\\b]+\\")|([A-Za-z0-9_\\!\\#\\$\\%\\&\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[A-Za-z0-9_\\!\\#\\$\\%\\&\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]{2,}))$/';
        if (preg_match($pattern, $value->email)) {
            return true;
        }
        $this->errors[] = new ValidationError('The value must be a valid email address.', null, array(), 'email');
        return false;
    }

Usage Example

 /**
  * Tests validating a wrong value.
  *
  * @covers \eZ\Publish\Core\FieldType\Validator\EmailAddressValidator::validate
  */
 public function testValidateWrongEmailAddresses()
 {
     $validator = new EmailAddressValidator();
     $validator->Extent = 'regex';
     $emailAddresses = array('*****@*****.**', 'Info-at-eZ.No');
     foreach ($emailAddresses as $value) {
         $this->assertFalse($validator->validate(new EmailAddressValue($value)));
     }
 }
All Usage Examples Of eZ\Publish\Core\FieldType\Validator\EmailAddressValidator::validate
EmailAddressValidator