如何检查输入字符串是否为x.y
?
答案 0 :(得分:1)
试试这段代码,
NSString *nameRegex =@"[0-9]+\\.[0-9]$";
NSPredicate *nameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nameRegex];
BOOL isDecimalNumber=[nameTest evaluateWithObject:string];
答案 1 :(得分:0)
还有一个解决方案。
NSString *str = @"123456";
NSCharacterSet *decimalSet = [NSCharacterSet decimalDigitCharacterSet];
BOOL valid = [[str stringByTrimmingCharactersInSet: decimalSet] isEqualToString:@""];