affc Posted August 8, 2008 Share Posted August 8, 2008 Hello all, I am trying to do a php check to make sure the input of the field is actually alphanumeric for the NAME that also allows uppercase, and the username that cannot accept Uppercase, please does anyone knwo why this code is not working? Just processes it as complete everytime. <?php $NAME=$_POST['NAME']; $Username=$_POST['Username']; if (preg_match('/[^A-Za-z0-9]/', $NAME)){ header("Location:complete.php"); } else{ header("Location:error.php"); } if (preg_match('/[^a-z0-9]/', $Username)){ header("Location:complete.php"); } else{ header("Location:error.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You need to put exit; after your header("Location:") calls. And you can't have an elseif where you have it...And you only want to redirect to complete.php if EVERYTHING checks out. Oh yeah and you don't need a regex for this. Just use ctype_alnum(). if (!ctype_alnum($NAME)) { $error = true; } if (!ctype_alnum($Username)) { $error = true; } if ($error) { header("Location: error.php"); } else { header("Location: complete.php"); } Just an idea. Not necessarily how I'd do validation, but it gets the job done. Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-611614 Share on other sites More sharing options...
affc Posted August 9, 2008 Author Share Posted August 9, 2008 Awesome thanx, Only problem is the Username I wanted to have it limit to only lowercase and the NAME to have both lowercase and uppercase, Regards Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-612172 Share on other sites More sharing options...
MasterACE14 Posted August 9, 2008 Share Posted August 9, 2008 use strtolower(); Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-612176 Share on other sites More sharing options...
affc Posted August 16, 2008 Author Share Posted August 16, 2008 Awesome, thanx, Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-617911 Share on other sites More sharing options...
affc Posted August 16, 2008 Author Share Posted August 16, 2008 Just discovered that it actually just changes the field to all lowercase eg : FieLd - will change to - field. I need it to be able to produce the error if it is not lower case alpha numeric. As the user will then need to change the username to lowercase manually so they are aware when its processed its all in lowercase, can this be done as I cannot find a way to do it? Thanx Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-617930 Share on other sites More sharing options...
affc Posted August 16, 2008 Author Share Posted August 16, 2008 Oh sorry doesn't matter as i created an acho to let people know their username once complete Thanx for the help Link to comment https://forums.phpfreaks.com/topic/118790-validate-field/#findComment-617966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.