0

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?

Tobia
  • 9,165
  • 28
  • 114
  • 219

1 Answers1

0

I have solved by adding this line in the application bootstrap:

\Respect\Validation\Validator::with("\\App\\Validation\\Rules\\");
reformed
  • 4,505
  • 11
  • 62
  • 88
Tobia
  • 9,165
  • 28
  • 114
  • 219