Reputation: 1913
I need to check if string has anything else than what specified below
everything else should not be in this string have have
i am stuck on this:
preg_match('/^[\w]{4,35}$/i', $username)
Upvotes: 2
Views: 231
Reputation: 26930
preg_match('/^[\w]{4,35}$/i', $username)
OK lets see what this doesn't work :
Match the beginning of the string, followed by [a-zA-Z0-9_] at least 4 times with a maximum of 35 times. This is quite different from your requirements.
Instead what you should use :
/^[a-zA-Z][-,.\w]{3,34}$/
The case sensitivity i modifier is not needed. Also I don't think this is exactly what you want. Usually you would need to specify a minimum length which you don't. This can match "a" for example (not a good username)
Upvotes: 2
Reputation: 1545
if( !preg_match('/^[a-zA-Z][a-zA-Z0-9_,.-]*$/', $username ))
echo "failed\n";
Upvotes: 7