ag3nt42 Posted May 29, 2008 Share Posted May 29, 2008 Hello again all, I find myself in a situation where I can't have the user put in wrong information or the process I have going will screw up.. And There is to much variation in the input to restrict it to a selection box. or the like... I want to be able to tell the text input which characters its allowed to accept and in what format... any one have ne ideas on this one? ??? ~thanks all. Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/ Share on other sites More sharing options...
FlyingIsFun1217 Posted May 29, 2008 Share Posted May 29, 2008 Maybe have an array of dis/allowed characters, and do a check to see if they are contained within the result? FlyingIsFun1217 Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-552996 Share on other sites More sharing options...
The Little Guy Posted May 30, 2008 Share Posted May 30, 2008 The following will only accept numbers and letters: $str = 'This is a string with the number 01.'; $isGood = FALSE; foreach(str_split($str) as $val){ if(ctype_alnum($val)){ $isGood = TRUE; }else{ $isGood = FALSE; } } if($isGood){ echo "String is valid."; }else{ echo "String is not valid."; } Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-553133 Share on other sites More sharing options...
ag3nt42 Posted May 30, 2008 Author Share Posted May 30, 2008 i need it to restrict input like this: must be 4 char long exactly no letters just num. Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-553185 Share on other sites More sharing options...
Gighalen Posted May 30, 2008 Share Posted May 30, 2008 i need it to restrict input like this: must be 4 char long exactly no letters just num. Get fancy with some if/else http://us.php.net/manual/en/function.strlen.php http://us.php.net/manual/en/function.is-numeric.php Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-553186 Share on other sites More sharing options...
haku Posted May 30, 2008 Share Posted May 30, 2008 if(!ereg("^[0-9]+$", $_POST['input']) || strlen($_POST['input']) > 4 || strlen($_POST['input']) < 4) { die("error"); } else { echo "success"; } Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-553187 Share on other sites More sharing options...
ag3nt42 Posted May 30, 2008 Author Share Posted May 30, 2008 if(!ereg("^[0-9]+$", $_POST['input']) || strlen($_POST['input']) > 4 || strlen($_POST['input']) < 4) { die("error"); } else { echo "success"; } precisely what I was looking for.. thanks you much haku.. i only had to alter it alil bit.. /////////////////////////// /// Validate Year Input /// /////////////////////////// if (!(isset($_GET['year']))) { echo(""); } else { if(!ereg("^[0-9]+$", $_GET['year']) || strlen($_GET['year']) > 4 || strlen($_GET['year']) < 4) { die("<script>alert(VAL);</script>"); } else { echo "success"; } } Link to comment https://forums.phpfreaks.com/topic/107876-solved-php-forms-picky-text-inputs/#findComment-553451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.