Jump to content

zip code not working


adi123

Recommended Posts

I have a zip code with this pattern

       if(preg_match("/zip/i",$field))
       {
         if(!preg_match("/^[0-9]{5,5}(\-[0-9]{4,4})?$/",
                        $value))
         {
            $errors[] = "$value is not a valid zipcode.";
         }
       }

the zip code is formed using the code below:

 

function getStateCode()
{
$stateCode = array(1=> "AL" ,
      "AK" ,
      "AZ" ,
      "AR" ,
      "CA" ,
      "CO" ,
      "CT" ,
      "DE" ,
      "DC" ,
      "FL" ,
      "GA" ,
      "HI" ,
      "ID" ,
      "IL" ,
      "IN" ,
      "IA" ,
      "KS" ,
      "KY" ,
      "LA" ,
      "ME" ,
      "MD" ,
      "MA" ,
      "MI" ,
      "MN" ,
      "MS" ,
      "MO" ,
      "MT" ,
      "NE" ,
      "NV" ,
      "NH" ,
      "NJ" ,
      "NM" ,
      "NY" ,
      "NC" ,
      "ND" ,
      "OH" ,
      "OK" ,
      "OR" ,
      "PA" ,
      "RI" ,
      "SC" ,
      "SD" ,
      "TN" ,
      "TX" ,
      "UT" ,
      "VT" ,
      "VA" ,
      "WA" ,
      "WV" ,
      "WI" ,
      "WY" );
return $stateCode;
}

function getStateName()
{
  $stateName = array(1=> "Alabama", 
      "Alaska", 
      "Arizona", 
      "Arkansas", 
      "California", 
      "Colorado", 
      "Connecticut", 
      "Delaware", 
      "District of Columbia", 
      "Florida", 
      "Georgia", 
      "Hawaii", 
      "Idaho", 
      "Illinois", 
      "Indiana", 
      "Iowa", 
      "Kansas", 
      "Kentucky", 
      "Louisiana", 
      "Maine", 
      "Maryland", 
      "Massachusetts", 
      "Michigan", 
      "Minnesota", 
      "Mississippi", 
      "Missouri", 
      "Montana", 
      "Nebraska", 
      "Nevada", 
      "New Hampshire", 
      "New Jersey", 
      "New Mexico", 
      "New York", 
      "North Carolina", 
      "North Dakota", 
      "Ohio", 
      "Oklahoma", 
      "Oregon", 
      "Pennsylvania", 
      "Rhode Island", 
      "South Carolina", 
      "South Dakota", 
      "Tennessee", 
      "Texas", 
      "Utah", 
      "Vermont", 
      "Virginia", 
      "Washington", 
      "West Virginia", 
      "Wisconsin", 
      "Wyoming");
return $stateName;
}

 

The code above doesn't form a valid zip code

CODE tags are neat.

Link to comment
Share on other sites

The code above doesn't form a valid zip code

It doesn't form any kind of zip code at all. The only things you posted (1) do a couple quick zip code-related tests on a couple variables and (2) return arrays of state names and abbreviations. There are no zip codes anywhere. There is nothing that creates zip codes.

Perhaps you forgot to post something?

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.