Jump to content

Archived

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

adi123

zip code not working

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.

Share this post


Link to post
Share on other sites

How are you fiing a zip code from those two arrays.

 

And your regexp doesn't need a min, max if they are the same, see revised.

         if(!preg_match("/^[0-9]{5}(\-[0-9]{4})?$/",

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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