Example #1
0
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->set('notify_emails', []);
     if (!$form_state->isValueEmpty('update_notify_emails')) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if ($this->emailValidator->isValid($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state->set('notify_emails', $valid);
         } elseif (count($invalid) == 1) {
             $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public static function validateValue(array &$element, FormStateInterface $form_state, array $form)
 {
     if (!empty($element['#value'])) {
         $validator = new EmailValidator();
         if (!$validator->isValid($element['#value'], TRUE)) {
             $form_state->setError($element, t('The entered email address is not valid.'));
         }
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  *
  * @param string $value The email to set in the object
  */
 public function __construct($value)
 {
     $validator = new EmailValidator();
     if (!$validator->isValid($value, new RFCValidation())) {
         throw new \InvalidArgumentException(sprintf('The passed value "%s" does not look like an email.', $value));
     }
     $this->email = $value;
     list($this->mailBox, $this->host) = explode('@', $this->email);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function isValid($emailAddress)
 {
     /**
      * Creates a new instance of the underlying validator class
      * on each validation request to avoid problems related to
      * state in the validator implementation
      */
     $baseValidator = new BaseEmailValidator();
     return $baseValidator->isValid($emailAddress, false, true);
 }
Example #5
0
 /**
  * @param mixed $data
  * @param bool $omitMandatoryCheck
  * @throws Model\Element\ValidationException
  */
 public function checkValidity($data, $omitMandatoryCheck = false)
 {
     if (!$omitMandatoryCheck && strlen($data) > 0) {
         $validator = new EmailValidator();
         if (!$validator->isValid($data, new RFCValidation())) {
             throw new Model\Element\ValidationException("Value in field [ " . $this->getName() . " ] isn't a valid email address");
         }
     }
     parent::checkValidity($data, $omitMandatoryCheck);
 }
 public function testIdGenerateId()
 {
     $idGenerator = new Swift_Mime_IdGenerator('example.net');
     $emailValidator = new EmailValidator();
     $id = $idGenerator->generateId();
     $this->assertTrue($emailValidator->isValid($id, new RFCValidation()));
     $this->assertEquals(1, preg_match('/^.{32}@example.net$/', $id));
     $anotherId = $idGenerator->generateId();
     $this->assertNotEquals($id, $anotherId);
 }
Example #7
0
 /**
  * @param EmailValidator $emailValidator
  * @param string|null    $idRight
  */
 public function __construct(EmailValidator $emailValidator, $idRight = null)
 {
     if ($idRight) {
         $this->idRight = $idRight;
     } else {
         $this->idRight = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated';
         if (!$emailValidator->isValid('dummy@' . $this->idRight)) {
             $this->idRight = 'swift.generated';
         }
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Validate and each email recipient.
     $recipients = explode(',', $form_state->getValue('recipients'));
     foreach ($recipients as &$recipient) {
         $recipient = trim($recipient);
         if (!$this->emailValidator->isValid($recipient)) {
             $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
         }
     }
     $form_state->setValue('recipients', $recipients);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) {
         // We want the literal %author placeholder to be emphasized in the error message.
         $form_state->setErrorByName('recipient', t('Enter a valid email address or use a token email address such as %author.', array('%author' => '[node:author:mail]')));
     }
 }
Example #10
0
 /**
  * {@inheritdoc}
  *
  * @param Email $value
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value || '' === $value) {
         return $value;
     }
     if (!$value instanceof Email) {
         $type = is_object($value) ? get_class($value) : gettype($value);
         throw new \InvalidArgumentException(sprintf('You have to pass an object of kind \\SerendipityHQ\\Component\\ValueObjects\\Email\\Email to use the Doctrine type EmailType. "%s" passed instead.', $type));
     }
     // Validate the $value as a valid email
     $validator = new EmailValidator();
     if (!$validator->isValid($value, new RFCValidation())) {
         throw new \InvalidArgumentException(sprintf('An email field accepts only valid email addresses. The value "%s" is not a valid email.', $value));
     }
     // The value is automatically transformed into a string thans to the __toString() method
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof Email) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Email');
     }
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (null === $constraint->strict) {
         $constraint->strict = $this->isStrict;
     }
     if ($constraint->strict && class_exists('\\Egulias\\EmailValidator\\EmailValidator')) {
         $strictValidator = new StrictEmailValidator();
         $valid = $strictValidator->isValid($value, false, true);
     } elseif ($constraint->strict === true) {
         throw new \RuntimeException('Strict email validation requires egulias/email-validator');
     } else {
         $valid = preg_match('/.+\\@.+\\..+/', $value);
     }
     if ($valid) {
         $host = substr($value, strpos($value, '@') + 1);
         // Check for host DNS resource records
         if ($valid && $constraint->checkMX) {
             $valid = $this->checkMX($host);
         } elseif ($valid && $constraint->checkHost) {
             $valid = $this->checkHost($host);
         }
     }
     if (!$valid) {
         $this->context->addViolation($constraint->message, array('{{ value }}' => $this->formatValue($value)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Validate and each email recipient.
     $recipients = explode(',', $form_state->getValue('recipients'));
     foreach ($recipients as &$recipient) {
         $recipient = trim($recipient);
         if (!$this->emailValidator->isValid($recipient)) {
             $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
         }
     }
     $form_state->setValue('recipients', $recipients);
     $redirect_url = $form_state->getValue('redirect');
     if ($redirect_url && $this->pathValidator->isValid($redirect_url)) {
         if (Unicode::substr($redirect_url, 0, 1) !== '/') {
             $form_state->setErrorByName('redirect', $this->t('The path should start with /.'));
         }
     }
 }
Example #13
0
 /**
  * Throws an Exception if the address passed does not comply with RFC 2822.
  *
  * @param string $address
  *
  * @throws Swift_RfcComplianceException If address is invalid
  */
 private function assertValidAddress($address)
 {
     if (!$this->emailValidator->isValid($address)) {
         throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.');
     }
 }
Example #14
0
//include ('thatfunk/fakefeed.txt');
echo '<div class="large-6 small-6 columns" style="padding-left: 1px; padding-right: 1px;margin-right: 0px;margin-left: 0px;">';
//echo 'Link: ', $atom->link;
echo '<h2>aerth\'s Github Log</h2><p><a href="https://github.com/aerth">View on Github</a><hr>';
foreach ($atom->entry as $item) {
    $description = str_replace('<a href="', '<a href="https://github.com/', $item->content);
    $description = str_replace('https://github.com/http', 'http', $description);
    $description = str_replace('https://github.com//', 'https://github.com/', $description);
    echo '<h4>';
    echo $item->title;
    echo '</h4>';
    echo '<br>';
    echo $description;
    echo '<hr>';
}
echo '</div>';
//var_dump($atom->entry['0']->link);
if ($_POST['subscribe_email']) {
    $email = $_POST['subscribe_email'];
    $validator = new EmailValidator();
    if ($validator->isValid($email)) {
        //  echo $email . ' is a valid email address';
        $log->addInfo($email . ' is a valid email address.');
        file_put_contents("../email.txt", $_POST['subscribe_email'] . ", ", FILE_APPEND);
        $subscribed = true;
    } else {
        $log->addInfo($email . ' is not a valid email address.');
    }
}
include 'thatfunk/footer.php';
die;
Example #15
0
 /**
  * Helper to validate a email address
  *
  * @static
  * @param $emailAddress
  * @return string | null - returns "null" if the email address is invalid otherwise the email address is returned
  */
 public static function validateEmailAddress($emailAddress)
 {
     $emailAddress = trim($emailAddress);
     $validator = new EmailValidator();
     if ($validator->isValid($emailAddress, new RFCValidation())) {
         return $emailAddress;
     }
     return null;
 }
 /**
  * Throws an Exception if the id passed does not comply with RFC 2822.
  *
  * @param string $id
  *
  * @throws Swift_RfcComplianceException
  */
 private function assertValidId($id)
 {
     if (!$this->emailValidator->isValid($id, new RFCValidation())) {
         throw new Swift_RfcComplianceException('Invalid ID given <' . $id . '>');
     }
 }
Example #17
0
 /**
  * Throws an Exception if the address passed does not comply with RFC 2822.
  *
  * @param string $address
  *
  * @throws Swift_RfcComplianceException If invalid.
  */
 private function assertValidAddress($address)
 {
     if (!$this->emailValidator->isValid($address, new RFCValidation())) {
         throw new Swift_RfcComplianceException('Address in mailbox given [' . $address . '] does not comply with RFC 2822, 3.6.2.');
     }
 }
 public function IsAdminUserUpdateValid(LoginUser $user)
 {
     $valid = true;
     $errors = array();
     $loadedUser = $this->app['phpdraft.LoginUserRepository']->LoadById($user->id);
     if ($user->id == 0 || empty($loadedUser)) {
         $valid = false;
         $errors[] = "Invalid user.";
         //Because we need to compare new & old values, we need a valid user record to proceed with vaidation.
         return new PhpDraftResponse($valid, $errors);
     }
     //Need to verify new email
     if (!empty($user->email) && !StringUtils::equals($user->email, $loadedUser->email)) {
         if (strlen($user->email) > 255) {
             $errors[] = "Email is above maximum length.";
             $valid = false;
         }
         $emailValidator = new EmailValidator();
         if (!$emailValidator->isValid($user->email)) {
             $errors[] = "Email is invalid.";
             $valid = false;
         }
         if (!$this->app['phpdraft.LoginUserRepository']->EmailIsUnique($user->email)) {
             $errors[] = "Email already registered.";
             $valid = false;
         }
     }
     if (strlen($user->name) > 100) {
         $errors[] = "Name is above maximum length";
         $valid = false;
     }
     if (!$this->app['phpdraft.LoginUserRepository']->NameIsUnique($user->name, $user->id)) {
         $errors[] = "Name already taken.";
         $valid = false;
     }
     return new PhpDraftResponse($valid, $errors);
 }
Example #19
0
<?php

use Egulias\EmailValidator\EmailValidator;
require __DIR__ . '/../../bootstrap.php';
$iterations = 10000;
$testingMail = '*****@*****.**';
echo 'Testing ' . $iterations . ' iterations with ' . $testingMail . PHP_EOL;
$a = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
    $isValid = filter_var($testingMail, FILTER_VALIDATE_EMAIL);
}
$b = microtime(true);
echo $b - $a . ' seconds with filter_var' . PHP_EOL;
$a = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
    $validator = new EmailValidator();
    $isValid = $validator->isValid($testingMail);
}
$b = microtime(true);
echo $b - $a . ' seconds with EmailValidator + instantiation' . PHP_EOL;
$a = microtime(true);
$validator = new EmailValidator();
for ($i = 0; $i < $iterations; $i++) {
    $isValid = $validator->isValid($testingMail);
}
$b = microtime(true);
echo $b - $a . ' seconds with EmailValidator once instanced' . PHP_EOL;
Example #20
0
 /**
  * fonction qui permet de vérifié si le champs nom est conforme
  * @param $value
  * @param null $required
  * @return bool
  */
 protected function setVerifMail($value, $required = null)
 {
     $validator = new EmailValidator();
     //test avec le required, si le champe est vide et que le required est != null on return fa	lse sinon on va tester
     if ($required != null && $this->getTestRequired($value) === false) {
         $this->erreur .= "<li>Le champs E-mail ne peut pas être vide</li>";
         return false;
     } else {
         if (!$validator->isValid($value)) {
             $this->erreur .= "<li>Le champs E-mail doit être une adresse E-mail valide</li>";
             return false;
         } else {
             $this->mail = $value;
             return true;
         }
     }
 }
 public function testInvalidUTF8Email()
 {
     $validator = new EmailValidator();
     $email = "���@���.���";
     $this->assertFalse($validator->isValid($email));
 }
Example #22
0
 /**
  * Returns true if the provided email is valid
  * @param string $em The email address to be tested
  * @param bool $testMXRecord Set to true if you want to perform dns record validation for the domain, defaults to false
  * @return bool
  */
 public function email($em, $testMXRecord = false)
 {
     $validator = new EmailValidator();
     return $validator->isValid($em, $testMXRecord, $testMXRecord);
 }
Example #23
0
 /**
  * Static helper to validate a email address
  *
  * @static
  * @param $emailAddress
  * @return bool
  */
 public static function isValidEmailAddress($emailAddress)
 {
     $validator = new EmailValidator();
     return $validator->isValid($emailAddress, new RFCValidation());
 }