I have a name field and I want to validate, so the first char must be alphabetical of the name and allow spaces and dashes after. I have this so for but it will allow “-” as first char.
preg_match("/^([a-z -])+$/i", $str)
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Being specific is the better option. But you can also use an assertion:
The
(?!..)can exclude characters from occuring first. You could also use a positive assertion like(?=\w).