regular expression in iOS

前端 未结 4 1335
清酒与你
清酒与你 2020-12-06 05:44

I am looking for a regular expression to match the following -100..100:0.01. The meaning of this expression is that the value can increment by 0.01 and should b

4条回答
  •  庸人自扰
    2020-12-06 05:54

              if(val>= -100 && val <= 100)
        {
            NSString* valregex = @"^[+|-]*[0-9]*.[0-9]{1,2}"; 
            NSPredicate* valtest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", valregex]; 
            ret = [valtest evaluateWithObject:txtLastname.text];
            if (!ret)
            {
                [alert setMessage:NSLocalizedString(@"More than 2 decimals", @"")];
                [alert show];       
            }
        }
    

    works fine.. Thnx for the efforts guys !

提交回复
热议问题