Source of file SlugRule.php
Size: 0,846 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Validator/Rule/SlugRule.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Validator\Rule; /** * Check for slug by regular expressions * * @package Bluz\Validator\Rule */ class SlugRule extends AbstractRule { /** * @var string error template */ protected $description = 'must be a valid slug'; /** * Check input data * * @param string $input * * @return bool */ public function validate($input): bool { if (false !== strpos($input, '--')) { return false; } if (!preg_match('/^[0-9a-z\-]+$/', $input)) { return false; } if (preg_match('/^-|-$/', $input)) { return false; } return true; } } |