在UITextBoxfield
,我插入一些值,我想使用RegularExpressions匹配字符串..现在我想文本框文本应该匹配只有数字高达3当我按下按钮然后它应该工作... 我正在尝试的是哪个不工作:: -NSString不工作的NSRegularExpression
-(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? – JustSid
只有999个数字 – Christien