Jump to content

eregi error


KevinM1

Recommended Posts

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.