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} 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. 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) 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. Link to comment https://forums.phpfreaks.com/topic/22108-username-validation/#findComment-98987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.