iOS-判断字符串是否非负整数

+ (BOOL)isText:(NSString *)text pattern:(NSString *)pattern{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
    return [predicate evaluateWithObject:text];
}

/**
 * 判断字符串是否非负整数
 * param iPAddress IP地址字符串
 * return BOOL 是返回YES,否返回NO
 */
+ (BOOL)isNonNegativeInt:(NSString *)nonNegativeInt{
    NSString *pattern = @"^\\d+$";
    return [self isText:nonNegativeInt pattern:pattern];
}

你可能感兴趣的:(iOS-判断字符串是否非负整数)