user4fun Posted December 14, 2007 Share Posted December 14, 2007 $name = $_REQUEST['name'];$t1 = $_REQUEST['t1'];$t2 = $_REQUEST['t2'];$t3 = $_REQUEST['t3'];$entry = $_REQUEST['entry'];$min_entry = "50000";//t1, t2, and t3 are the users phone number starting with area codeI need to validate that $name is not emptyother wise go to name_error.phpTHEN$t1 is not less OR more that 3 chracters 0 to 9Other wise go to ac_error.php$t2 is not less OR more that 3 characters 0 to 9 AND $t3 is not less OR more that 4 digits 0 to 9Other wise go to number_error.php$entry is not less than $min_entry and only using chracters 0 to 9If all the above is OK then //more codeIt is duable, except I don't know how to NOT repeat the 0 to 9 stipulation of number of chracters.Also, I am not sure if it would be if...else of elseifPlease help Link to comment Share on other sites More sharing options...
justsomeguy Posted December 14, 2007 Share Posted December 14, 2007 This is the low-tech way, without regular expressions. Regexp will give you a better match, but I've been drinking and I don't want to think about regexp right now. $name is not emptyother wise go to name_error.php if ($name == ""){ header("Location: name_error.php"); exit();} $t1 is not less OR more that 3 chracters 0 to 9Other wise go to ac_error.php if (strlen($t1) != 3 || intval($t1) != $t1){ header("Location: ac_error.php"); exit();} $t2 is not less OR more that 3 characters 0 to 9 AND $t3 is not less OR more that 4 digits 0 to 9Other wise go to number_error.php if (strlen($t2) != 3 || intval($t2) != $t2 || strlen($t3) != 4 || intval($t3) != $t3){ header("Location: number_error.php"); exit();} $entry is not less than $min_entry and only using chracters 0 to 9 if ($entry < $min_entry || !preg_match('^\d+$', $entry)){ echo "bah!";}else{ // more code} Damnit, you got me to use regexp. Link to comment Share on other sites More sharing options...
user4fun Posted December 14, 2007 Author Share Posted December 14, 2007 lolyou are funny, thank you I will try that code today.Thanks alot Link to comment Share on other sites More sharing options...
user4fun Posted December 14, 2007 Author Share Posted December 14, 2007 if ($entry < $min_entry || !preg_match('^\d+$', $entry)){ echo "bah!";}I dont understand this part? Link to comment Share on other sites More sharing options...
boen_robot Posted December 14, 2007 Share Posted December 14, 2007 I dont understand this part?If$entry is not less than $min_entry and only using chracters 0 to 9thenecho "bah!"; Link to comment Share on other sites More sharing options...
user4fun Posted December 15, 2007 Author Share Posted December 15, 2007 So at the bah area that is when all the information is in good shape and I can start the code??? Link to comment Share on other sites More sharing options...
Synook Posted December 15, 2007 Share Posted December 15, 2007 No, I think boen_robot meant to sayIf $entry is less than $min_entry or uses characters other than 0 to 9thenecho "bah!"; So then the $entry is invalid. Link to comment Share on other sites More sharing options...
user4fun Posted December 16, 2007 Author Share Posted December 16, 2007 Thank you,for some reason if the entry box has abcde chracters in it, it accepts the entry.It is not validatin 0 to 9 digits?$min_entry = "5000"; Link to comment Share on other sites More sharing options...
zppblood Posted December 16, 2007 Share Posted December 16, 2007 If it accepts anything that is non-numeric, and you want to only have numbers you can use functions like is_numeric(), intval(), floatval(), etc. Link to comment Share on other sites More sharing options...
Synook Posted December 16, 2007 Share Posted December 16, 2007 Ah wait using Regex it should be like this if ($entry < $min_entry || preg_match('^\d+$', $entry)){echo "bah!";} Link to comment Share on other sites More sharing options...
justsomeguy Posted December 17, 2007 Share Posted December 17, 2007 This should work: if ($entry < $min_entry || !preg_match('^\d+$', $entry)){ echo "the entry was less then the min entry, or it contained something other then digits";}else{ // more code} The if statement says that if the entry is less then min_entry, or if it does not match the expression, then go to the first case. So that means the first case is the failure case. If you want the first case to be the successful case you can reverse the logic. if ($entry >= $min_entry && preg_match('^\d+$', $entry)){ echo "the entry was longer then the minimum and contained only digits";}else{ // more code} Link to comment Share on other sites More sharing options...
user4fun Posted December 21, 2007 Author Share Posted December 21, 2007 This is exactly how I have itWhen i put ancd instead of numbers it gives me the errorif I put in 64574673654Which is larger that $min_entry which is 5000 it still gives me the error??? if ($entry < $min_entry || !preg_match('^\d+$', $entry)) { header("Location: entry_error.php"); exit();}else{ echo "good";} Link to comment Share on other sites More sharing options...
justsomeguy Posted December 21, 2007 Share Posted December 21, 2007 Change it to this:if (!preg_match('^\d+$', $entry) || intval($entry) < $min_entry)It might be a numeric string, but there's nothing really complex about that if statement. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.