EXiT Posted April 5, 2008 Share Posted April 5, 2008 Hi, Im looking for a function that will only allow the user to signup with the characters: a-z, A-Z, 0-9, - and _ for the username and password fields. Any code or websites that will show me how this is done, would be great. Cheers Link to comment https://forums.phpfreaks.com/topic/99736-usernamepassword-characters/ Share on other sites More sharing options...
uniflare Posted April 5, 2008 Share Posted April 5, 2008 to validate user input i personally use preg_match. to validate your example you could use this pattern: if(preg_match("/\A[A-Za-z0-9_-]{4,16}",$_POST['username']) != 1){ echo("Username must be Letters,Numbers,dashes and underscores only, must also be wtween 4 and 16 characters long."); }else{ // Username Okay } http://uk.php.net/manual/en/reference.pcre.pattern.syntax.php for more information on perl-compatible php regular expressions. Link to comment https://forums.phpfreaks.com/topic/99736-usernamepassword-characters/#findComment-510181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.