Bluz\Validator\Rule\Slug::validate PHP Method

validate() public method

Check input data
public validate ( string $input ) : boolean
$input string
return boolean
    public function validate($input) : bool
    {
        if (strstr($input, '--')) {
            return false;
        }
        if (!preg_match('/^[0-9a-z\\-]+$/', $input)) {
            return false;
        }
        if (preg_match('/^-|-$/', $input)) {
            return false;
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * @dataProvider providerForFail
  * @expectedException \Bluz\Validator\Exception\ValidatorException
  */
 public function testInvalidSlug($input)
 {
     $this->assertFalse($this->validator->validate($input));
     $this->assertFalse($this->validator->assert($input));
 }