I learn regular expression, so please calm down with me!
The username is considered valid if it does not start with _ (underscore) and contains only the word characters (letters, numbers and underscore):
namespace Gremo\ExtraValidationBundle\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; class UsernameValidator extends ConstraintValidator { public function validate($value, Constraint $constraint) {
To combine them into one regex , I tried the following:
^_+[^\w]+$
To read how: add a violation if it starts with an underscore (in the end, more than one), and if at least one character is not allowed (not a letter, number or underscore). For example, does not work with "_test".
Can you help me figure out where I am going wrong?
gremo source share