I am working on a symfony(2.8) project. Where in the registration form needs some input validation. I need to set following constraints on the Subdomain name input field: 1. Should contain only alphanumeric characters 2. First character can not be a number 3. No white spaces
I am using annotations for this task. Here is the Assert statement I am using:
@Assert\Regex(pattern="/^[a-zA-Z][a-zA-Z0-9]\s+$/", message="Subdomain name must start with a letter and can only have alphanumeric characters with no spaces", groups={"registration"})
When I enter any simple string of words eg. svits, it still shows the error message "Subdomain name must start with a letter and can only have alphanumeric characters with no spaces" Any suggestions would be appreciated.
pattern="/^[a-zA-Z][a-zA-Z0-9]*$/".\s+matches 1+ whitespaces, why add what you want to forbid?*at the end to allow 0 or more characters (and 1 letter words), or Toto's+to only allow 2 or more letter words.