vassy
(Yevreinov)
1
Hello.
What would be the best way to run Yii email validator outside of the model?
Ex.: user submits a list of emails (separated by commas), I explode them into array and need to run email validation for each item.
Should I create a dummy model or is there any better solution?
Thank you.
jayrulez
(Waprave)
2
(not tested).
$validator = new CEmailValidator;
if($validator->validateValue("test@domain.tld"))
{
// valid
}else{
// invalid
}
vassy
(Yevreinov)
3
CEmailValidator does not have a method named "validateValue".
jayrulez
(Waprave)
4
I just tested for myself and it works
$validator = new CEmailValidator;
if($validator->validateValue("test@gmail.com"))
echo "validated";
qwerty
(qwerty)
5
Try validateAttribute() method.
jayrulez
(Waprave)
6
Validate attribute works with models and does not return a boolean value.
read the source http://code.google.com/p/yii/source/browse/trunk/framework/validators/CEmailValidator.php
CEmailValidator::validateValue($value) is the method to use.
mbi
(mbi)
7
validateValue() is available in SVN but not in a official relase so far, isnt it?
driss
(Arendhel)
8
I usually use validateValue() wich does what needs to be done