EEmailValidator is a validator class which relies on Manuel Lemos' e-mail address validation class (see that class for further dependencies)
This validator performs basic regex validation and some advanced checks using getmxrr to verify the validity of a given e-mail address.
Manuel Lemos' class uses an alternate GetMXRR function from the DNSResolver code by Moriyoshi Koizumi, in case the getmxrr function is not available or is not working. His code is not OOP, so I tried to make PHP5 classes with it, but it's not fully tested, so, if you don't have a working getmxrr or are under windows, either use it under your own risk or send me patches ;)
Please read the source code for the meaning of the various properties.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
In the view:
<?php echo CHtml::activeLabel($user, 'email'); ?>
<?php echo CHtml::activeTextField($user, 'email',
array('title'=>Yii::t('demo', 'Enter your e-mail'))); ?>
<?php echo CHtml::error($user, 'email'); ?>
In the model:
<?php
class UserModel extends CFormModel
{
public $email;
public function rules()
{
return array(
array('email',
'application.extensions.emailvalidator.EEmailValidator',
'strictValidation'=>false),
);
}
public function attributeLabels()
{
return array(
'email'=>Yii::t('demo', 'Enter your e-mail address: '),
);
}
}
Goood!!!!
Good thing... i try to use emailsintaxvalidator... it`s most popular...but not working :D
This is good solution for me!
UPDATE PLEASE
Hi
Is there any chance this extension can be update. Its complaining that the function ereg is deprecated!
Cheers
i18n
I tried to translate the message 'The e-mail address is invalid', but it didn't work, but when I changed the Category from 'yii' to 'errors' it worked.
$message = $this->message !== null ? $this->message : Yii::t('errors', 'The e-mail address is invalid.');
From the documentation:
The category yii is reserved for messages used by the Yii Framework core code.
cheers
Answer at the forum
Hi jeanluca, I'm explaining at the forum.
Attention: "strictValidation = true" is not reliable
Be careful using the strict option, it might reject valid email addresses!
I changed EEmailValidator line 138 to just use the host validation:
if ((($result = $validator->ValidateEmailHost($email, $hosts))<0) && ($this->strictValidation)) $valid = false;
Thus I have a "medium-strict" variant, which is much more reliable to use for commercial websites.
btw: you can replace "ereg" by "preg_match" if you run on PHP 5.3
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.