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,559
  • 6
  • 29
  • 58

3 Answers3

5

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

Joshua Weinberg
  • 28,440
  • 2
  • 96
  • 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
  • 24,998
  • 7
  • 76
  • 97
0

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

NSDate