+ (BOOL)isText:(NSString *)text pattern:(NSString *)pattern{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",pattern];
return [predicate evaluateWithObject:text];
}
/**
* 判断字符串是否为IP地址
* param iPAddress IP地址字符串
* return BOOL 是返回YES,否返回NO
*/
+ (BOOL)isIPAddress:(NSString *)iPAddress{
NSString *pattern = @"^(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5]).(\\d{1,2}|1\\d\\d|2[0-4]\\d|25[0-5])$";
return [self isText:iPAddress pattern:pattern];
}
iOS-判断字符串是否为IP地址
最新推荐文章于 2021-02-16 18:33:01 发布