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
https://forums.phpfreaks.com/topic/240040-zip-code-not-working/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.