3

How can I check NSString is date or not? For example:

NSString - Jul 14 at 14.55 PM return TRUE

NSString - Talala... return False

Please help..

LightNight
  • 1,616
  • 6
  • 30
  • 59

3 Answers3

5

Assuming you're on iOS you can check that using NSDataDetector

Joshua Weinberg
  • 28,598
  • 2
  • 97
  • 90
2

You could use a NSDateFormatter and allow it to use an heuristic to determine if the given input string is a date or not (just call [formatter setLeninent:YES] for this). If it can create a NSDate object out of your NSString, congratulations, the string contains a date, otherwise it most likely doesn't.

JustSid
  • 25,168
  • 7
  • 79
  • 97
0

You can try creating a new NSDate instance giving the NSString and check wether the result is nil or not.

NSDate