Jump to content

preg_match help


gsmith
 Share

Recommended Posts

I am creating a page for users to create a username and password. I want the password to only contain the letters a-z, A-Z and/or numbers 0-9. If a user tries to use a special character other than them, I want to return an error message and have them try again. I thought I could do this with preg_match, but I can't seem to get it to work. This is what I've tried so far:if($username != "" || $password != ""){ $pattern="/^[!@#$%^&*_-+= ]*$/"; if (preg_match ($pattern, $username.$password)){ print($chr_err); include($login_page); exit(); }}I then try to create a username and password while purposelly using some of those characters, but I don't get the $chr_err message printed. Any help would be greatly appreciated!

Link to comment
Share on other sites

The following pattern will test for any "non-word" character or underscore in the string.

By non-word you mean a-z, A-Z, and 0-9 would be ok? I want to allow all of those - even if it doesn't spell a real word. I just want to dissallow underscore, space, and any other special characters.Thanks a lot for the help!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...