开发者

Check format of text entered in NSTextField

开发者 https://www.devze.com 2023-03-07 01:49 出处:网络
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 ha

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

精彩评论

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