gsmith Posted January 1, 2006 Share Posted January 1, 2006 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 More sharing options...
hacknsack Posted January 2, 2006 Share Posted January 2, 2006 The following pattern will test for any "non-word" character or underscore in the string. $pattern= "/[\W_]/"; Let us know if it needs tweaking.Thanks, Link to comment Share on other sites More sharing options...
gsmith Posted January 2, 2006 Author Share Posted January 2, 2006 The following pattern will test for any "non-word" character or underscore in the string.<{POST_SNAPBACK}> 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 More sharing options...
hacknsack Posted January 2, 2006 Share Posted January 2, 2006 You are welcome for the help, and yes that is what it does. Link to comment Share on other sites More sharing options...
gsmith Posted January 2, 2006 Author Share Posted January 2, 2006 Thank you! It worked great. W3Schools is where I started learning PHP. I then learned more on my own....now I'm back learning more again! Thank you! Link to comment Share on other sites More sharing options...
hacknsack Posted January 2, 2006 Share Posted January 2, 2006 Anytime, Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now