tags:

views:

17

answers:

2

I want to be able to validate a date.

It's valid entry is 4 characters with a mmyy mask.

I want to make sure that the value entered is indeed a date.

Thanks in advance.

A: 

User NSDateFormatter's -setDateFormat: and -dateFromString: methods. If the string is not in the correct format, you will get nil returned from -dateFromString:.

Graham Lee
+1  A: 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mmyy"];
NSDate *date = [dateFormatter dateFromString:YOUR_STRING];


If (date) { 
// CORRECT
}
vodkhang
thanks. And how to test for number?
butchcowboy
you can try with `[str intValue];`
vodkhang