Re: iPhone: validate a NSString for US zipcode
Re: iPhone: validate a NSString for US zipcode
- Subject: Re: iPhone: validate a NSString for US zipcode
- From: "Henry McGilton (Boulevardier)" <email@hidden>
- Date: Thu, 7 Jan 2010 09:32:19 -0800
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, Paul Bruneau <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?
>>>
>>
=================================================
iPhone App Development and Developer Education . . .
Visit www.nonatomic-retain.com
Mac OSX Application Development, Plus a Great Deal More . . .
Visit www.trilithon.com
_______________________________________________
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