pranshu82202 Posted August 22, 2011 Share Posted August 22, 2011 I have a form validation script which is written in php.. I want to add a validation (in registration form) that if the desired username contains either admin or owner keyword user will have to change his user name.. I made the following code but it does not work.. if(strpos($user_name, "admin")>=0 || strpos($user_name, "moderator")>=0 || strpos($user_name, "owner")>=0) { $error=$error."You are not allowed to take such Username<br>"; $bool=false; } In this code i am not able to enter any username.. And if i change >= to > then "admin123" username is going to be valid... I am troubled .... help me out guyzzz -pranshu.a.11@gmail.com Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/ Share on other sites More sharing options...
trq Posted August 22, 2011 Share Posted August 22, 2011 You'll want to check strpos() returns false. Instead of >=0 use === false Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/#findComment-1260459 Share on other sites More sharing options...
Muddy_Funster Posted August 22, 2011 Share Posted August 22, 2011 I think you actualy want === true for that check Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/#findComment-1260460 Share on other sites More sharing options...
Andy-H Posted August 22, 2011 Share Posted August 22, 2011 Use stristr Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/#findComment-1260461 Share on other sites More sharing options...
WebStyles Posted August 22, 2011 Share Posted August 22, 2011 if(strpos($user_name, "admin")!== false || strpos($user_name, "moderator")!== false || strpos($user_name, "owner")!== false) Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/#findComment-1260463 Share on other sites More sharing options...
pranshu82202 Posted August 22, 2011 Author Share Posted August 22, 2011 Yes admin and WebStyles the code worked correctly... Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/245417-php-validation/#findComment-1260465 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.