I'm using Respect Validation classes and I want to validate a list of email separated by , or ; and spaces like:
mymail1@mydomain.com; mymail2@mydomain.com,mymail3@mydomain.com ;mymail4@mydomain.com;
I cannot use the standard email() rule and I did not find any rule for a mixed comma, semi-colon and space list.
The I tried to create a custom rule class and I put this inside my App\\Validaton\\Rules folder.
namespace App\Validation\Rules;
use Respect\Validation\Rules\AbstractRule;
use Respect\Validation\Rules\Email;
class Emails extends AbstractRule
{
public function validate($input)
{
if (!is_string($input)) {
return false;
}
$inputs=preg_split( "/;|,/", $input);
$v=new Email();
foreach($inputs as $input){
if(!$v->validate($input))
return false;
}
return true;
}
}
How can I use my custom validator using static validator reference?
If I try this:
use \Respect\Validation\Validator as V
...
V::length(0,200)->emails()->validate($input);
I got:
"emails" is not a valid rule name
What I'm missing in the namespace inclusion?
我通过在应用程序引导程序中添加这一行来解决:
\Respect\Validation\Validator::with("\\App\\Validation\\Rules\\");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.