• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iPhone: validate a NSString for US zipcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iPhone: validate a NSString for US zipcode


  • Subject: Re: iPhone: validate a NSString for US zipcode
  • From: Steve Christensen <email@hidden>
  • Date: Thu, 07 Jan 2010 10:59:53 -0800

As others have pointed out, letting the service do the validation takes the onus off of your app to keep itself up-to-date.

If you get an error, though, I would let the user know that the zip code is invalid and give them an opportunity to fix it or choose a different one. The user shouldn't be bothered very often since running into an invalid zip code should only happen when it's being entered initially or if for some reason it later disappears.


On Jan 7, 2010, at 10:07 AM, Eric E. Dolecki wrote:

The webservice reports a city not found error - to which I can default to a
known zipcode instead.


On Thu, Jan 7, 2010 at 12:32 PM, Henry McGilton (Boulevardier) <
email@hidden> wrote:


On Jan 7, 2010, at 8:53 AM, Eric E. Dolecki wrote:

I don't care about the city, just that the zip code will work. On an iPhone
testing against an array of 42,305 values... could that be pretty quick?
Seems like a large set to go through looking. I'm sending the value to a
webservice to return weather data.



Time to read about Binary Search --- for a list that size you can find (or
not) a match in just 16 comparisons . . .


   Cheers,
       . . . . . . . .    Henry


On Thu, Jan 7, 2010 at 11:45 AM, <email@hidden> wrote:



I'm a little unclear what you are asking, but I'll tell what I know. You
just want to know if a 5 digit zip code is a valid one? Or do you want to
compare it to the list of valid city names that are assigned to it? (yes it
can be more than one, ugh)


They are (from a non-USPS point of view) arbitrarily assigned by the post
office and there are currently 42,305 or so assigned (out of a theoretical
maximum of 100,000 of course)


So assuming you just want to know if it's a valid zip (and don't care about
if they got the city right), the only way to validate it solely from within
your app as a valid zip code would be to have a list of them in your app.


You could load them from a plist or straight text I guess into an NSArray
or NSSet and then check to see if the zip is valid as needed.


You can get the list from a third party service like
http://www.zipcodeworld.com/ or maybe from some free source.

The value of this might be questionable, since a zip code with a typo still
has roughly a 50% chance of being a valid one. Plus the USPS is always
adding new ones, so will you risk telling your user that his zip code
doesn't exist when he is standing in it?


So I guess the answer is there is no Cocoa technology that can help with
this--unless you are asking something completely different, in which case
let's all have a good chuckle at my poor comprehension skills :)



On Jan 7, 2010, at 11:11 AM, Eric E. Dolecki wrote:

I've been googling but haven't seen yet how to best validate a 5- digit
zipcode for use in the US (without using a webservice).


I have the NSString, I just need to validate it. I know zero RegExp, is
there a formatter I can use?

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >iPhone: validate a NSString for US zipcode (From: "Eric E. Dolecki" <email@hidden>)
 >Re: iPhone: validate a NSString for US zipcode (From: Paul Bruneau <email@hidden>)
 >Re: iPhone: validate a NSString for US zipcode (From: "Eric E. Dolecki" <email@hidden>)
 >Re: iPhone: validate a NSString for US zipcode (From: "Henry McGilton (Boulevardier)" <email@hidden>)
 >Re: iPhone: validate a NSString for US zipcode (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: Re: Julian date
  • Next by Date: Re: Julian date
  • Previous by thread: Re: iPhone: validate a NSString for US zipcode
  • Next by thread: Re: iPhone: validate a NSString for US zipcode
  • Index(es):
    • Date
    • Thread