iOS判断是否为网址
2020-05-10 本文已影响0人
biubiuboom
- (BOOL)isUrlAddress:(NSString*)url
{
NSString*reg =@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";
NSPredicate*urlPredicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", reg];
return[urlPredicateevaluateWithObject:url];
}