UsernameValidator.php (607B)
1 <?php 2 3 namespace PartKeepr\AuthBundle\Validator\Constraints; 4 5 use Symfony\Component\Validator\Constraint; 6 use Symfony\Component\Validator\ConstraintValidator; 7 8 class UsernameValidator extends ConstraintValidator 9 { 10 public function validate($value, Constraint $constraint) 11 { 12 if (!preg_match('/^[a-zA-Za0-9.\-_\/\\\]{3,50}$/', $value, $matches)) { 13 // If you're using the new 2.5 validation API (you probably are!) 14 $this->context->buildViolation($constraint->message) 15 ->setParameter('%string%', $value) 16 ->addViolation(); 17 } 18 } 19 }