Check format of text entered in NSTextField
I've subclassed NSTextField
and need to check that the text entered into it is in the format of either 00:00:00 or 0:00:00 with textDidEndEditing
. I was about to go to regEx r开发者_JS百科oute but have read advice suggesting otherwise. Is there a more straightforward way of accomplishing this? Thanks in advance.
If you're wanting to use NSPredicate
, then you can simulate the use of regex by doing something like:
+(BOOL)text:(NSString*)content passesRegex:(NSString*)regex {
NSPredicate* regextest = [NSPredicate predicateWithFormat:
@"SELF MATCHES %@", regex];
return ([regextest evaluateWithObject:content] == YES);
}
精彩评论