bladez Posted September 12, 2007 Share Posted September 12, 2007 i have a form for login n password i want to validate on server site to check if the content are either characters or numbers only ... Example : Username : bladez - accecpted Username : bladez99 - accecpted Username : *>dsa*dad - Rejected Username : <?php bla ?> - rejected Which means if it doesnt meet those pattents its an error ..how do i do that in PHP? Quote Link to comment https://forums.phpfreaks.com/topic/69063-help-pls-validating-input-boxhow/ Share on other sites More sharing options...
hackerkts Posted September 12, 2007 Share Posted September 12, 2007 You can try regex a-zA-Z0-9 Quote Link to comment https://forums.phpfreaks.com/topic/69063-help-pls-validating-input-boxhow/#findComment-347136 Share on other sites More sharing options...
colombian Posted September 12, 2007 Share Posted September 12, 2007 To validate particular patterns, you'll need to venture into regular expressions. Here is a helpful tutorial: http://weblogtoolscollection.com/regex/regex.php Or just go to: http://us3.php.net/regex The number portion of it you can check with the is_numeric function. So <?php if (!is_numeric($POST['variable'])) { // Errors here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69063-help-pls-validating-input-boxhow/#findComment-347137 Share on other sites More sharing options...
AdRock Posted September 12, 2007 Share Posted September 12, 2007 You can do this if(!ereg("^[A-Za-z0-9 \-]{4,30}$",$username)) The bit that does [A-Za-z0-9] will allow numbers and letters only The bit that does {4,30} allows between 4 and 30 letters/numbers and $ username is the input box name Quote Link to comment https://forums.phpfreaks.com/topic/69063-help-pls-validating-input-boxhow/#findComment-347345 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.