开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜