master82 Posted September 26, 2006 Share Posted September 26, 2006 I've been having a few problems with users signing up with usernames that contain special characters, so I have decided to 'tweek' my registration authentication script to disallow special characters.So how would I go about validating a username input to check that it only contains letters, numbers or a mixture of both?egif($_POST['username'] != [color=navy]+letters and/or numbers+[/color]){something}else{something else} Quote Link to comment https://forums.phpfreaks.com/topic/22108-username-validation/ Share on other sites More sharing options...
Orio Posted September 26, 2006 Share Posted September 26, 2006 You should look into [b]Regular Expressions[/b].Orio. Quote Link to comment https://forums.phpfreaks.com/topic/22108-username-validation/#findComment-98951 Share on other sites More sharing options...
master82 Posted September 26, 2006 Author Share Posted September 26, 2006 Thanks for that - came up with this, but not sure exactly how to put it into the code.[code]ereg("^[0-9a-zA-Z]{4,10}$", "$username")[/code]Would this work...[code]if(ereg("^[0-9a-zA-Z]{4,10}$", "$username")){bla{else{bla bla}[/code]Also I understand the first part, it is looking for alphnumeric characters, but what is the {4,10} part doing? is this looking at the length? (a simple guess) Quote Link to comment https://forums.phpfreaks.com/topic/22108-username-validation/#findComment-98978 Share on other sites More sharing options...
KevinM1 Posted September 26, 2006 Share Posted September 26, 2006 Yes, the {4, 10} is looking at length. It specifies at least 4 characters, at most 10 characters. Quote Link to comment https://forums.phpfreaks.com/topic/22108-username-validation/#findComment-98987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.