Date validation
Date validation
- Subject: Date validation
- From: Andy Bettis <email@hidden>
- Date: Sun, 26 Jun 2005 10:17:55 +0100
Hi folks,
A lot of my apps require dates to be input, and to be validated on
input. As I have explained in earlier posts the NSDateFormatter
approach does not work for me so I need to write my own input
validation routine. As I'm a newbie to Cocoa I'd like your comments
on my plans.
The date format will always be dd/mm/yyyy although d and m can be one
character and yyyy can be yy (in which case I use a range of 1950 -
2050).
Initially I get the input string with [[inField stringValue]
stringByTrimmingCharactersInSet:whitespaceCharacterSet]. If the
resulting string is zero length I either flag it as an error if the
field is mandatory or supply the appropriate default.
I test the format by using rangeOfCharacterFromSet with a character
set of numerics plus '/'. If the range returned isn't the same as the
whole string I flag a format eror. If the string passes this test I
split it up with [theInput componentsSeparatedByString:@"/"] and flag
an error if there are not three components.
Next I convert each of the component strings into ints and do the
usual day, month and year range checks.
If no errors have been flagged I create a new NSDate object and pass
this back.
Is there a better/easier/faster/more Cocoish way to do this?
Many thanks
Rev. Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden