I need a simple regex that will work in preg_replace that will convert any input given it to the following rules:
1) First character must be A-Z or a-z
2) If there is more than 1 character, then the following character(s) must be A-Z, a-z, 0-9 or a space
I need any non-conforming characters to be removed and the resultant string to be returned.
I have this as the regex string:
/^[a-zA-Z][a-zA-Z0-9 ]*$/
I have a little regex experience, so I assume this should work, but when I try a string like:
1Athsj294-djs
Here:
http://www.functions-online.com/preg_replace.html
It is not working, please help. Thanks!
changes
into
Explanation:
The
/simodifiers make the regex case-insensitive and allow the dot to match newlines.