【发布时间】:2012-12-23 02:51:49
【问题描述】:
在UITextBoxfield,我插入了一些值,并且我想使用正则表达式匹配字符串..现在我希望文本框文本在我按下按钮时只匹配最多 3 位的数字,然后它应该可以工作.. .
我正在尝试的是哪个不起作用::-
-(IBAction)ButtonPress{
NSString *string =activity.text;
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^[0-9]{1,3}$" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@""];
if ([activity.text isEqualToString:modifiedString ])
{ // work only if this matches numeric value from the text box text
}}
【问题讨论】:
-
您到底想达到什么目标?只允许最多 999 的数字,还是只允许 0、1、2 和 3?
标签: iphone ios regex nsregularexpression