KevinM1 Posted December 22, 2006 Share Posted December 22, 2006 I'm currently trying to write some form validation into a script, but the eregi function keeps choking on one of my expressions. I keep getting the error: [quote]Warning: eregi() [function.eregi]: REG_ERANGE in /home/thinkin8/public_html/checkout.php on line 18[/quote]This error occurs where I try checking an address for validity. My code is:[code]<?php#checkout.php$errMessage = NULL;$mailMessage = NULL;if(isset($_POST['submit'])){ if(!empty($_POST['name']) && eregi("^[a-zA-Z]+([ a-zA-Z-]+)*$", $_POST['name'])){ $name = $_POST['name']; $n = TRUE; } else{ $errMessage .= "Please enter your name!<br />\n"; } if(!empty($_POST['address1']) && eregi("^[0-9a-zA-Z.- ]+$", $_POST['address1'])){ $address1 = $_POST['address1']; $a1 = TRUE; } else{ $errMessage .= "Please enter your address!<br />\n"; } if(!empty($_POST['address2']) && eregi("^[0-9a-zA-Z.- ]+$", $_POST['address2'])){ $address2 = $_POST['address2']; } else{ $address2 = ''; } if(!empty($_POST['city']) && eregi("^[a-zA-Z.- ]+$", $_POST['city'])){ $city = $_POST['city']; $c = TRUE; } else{ $errMessage .= "Please enter your city!<br />\n"; } if(!empty($_POST['state']) && eregi("^[a-zA-Z]{2}$", $_POST['state'])){ $state = $_POST['state']; $s = TRUE; } else{ $errMessage .= "Please enter your state!<br />\n"; } if(!empty($_POST['zipcode']) && eregi("^[0-9]{5}[-0-9]{4}?$", $_POST['zipcode'])){ $zipcode = $_POST['zipcode']; $z = TRUE; } else{ $errMessage .= "Please enter your zipcode!<br />\n"; } if($n && $a1 && $c && $s && $z){ $mailMessage .= "$name\n$address1\n$address2\n$city, $state $zipcode"; mail('kevin@thinkingmachineonline.com', 'Test message', $mailMessage); echo "Your mail has been sent, $name<br />\n"; } else{ echo "<div style='color: red;'>$errMessage</div>\n"; }}?><form name="checkout" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> Name: <input type="text" name="name" /><br /> Address 1: <input type="text" name="address1" /><br /> Address 2: <input type="text" name="address2" /><br /> City: <input type="text" name="city" /><br /> State: <input type="text" name="state" /><br /> Zipcode: <input type="text" name="zipcode" /><br /> <input type="submit" name="submit" value="Checkout" /></form>[/code]I'm just trying to see if the user entered in normal address stuff (alphanumeric characters, and the period, hyphen, and space), so I'm a bit at a loss as to why this error is appearing, especially when my first regex, which validates a person's name, works correctly. Please help. Quote Link to comment Share on other sites More sharing options...
Orio Posted December 22, 2006 Share Posted December 22, 2006 You need to escape the "-". Same goes for the full-stops.^[0-9a-zA-Z.- ]+$ For example should be ^[0-9a-zA-Z\.\- ]+$Orio. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted December 22, 2006 Author Share Posted December 22, 2006 Unfortunately, I'm still getting the same error. Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted December 22, 2006 Share Posted December 22, 2006 [code]eregi('^[a-zA-Z\.\-\ ]+$', 'foo');[/code] Quote Link to comment 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.