URL验证(Objective-C) [英] URL Validation (Objective-C)
本文介绍了URL验证(Objective-C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用此方法验证URL:
I am trying to validate a URL with this method:
代码:
- (BOOL) validateUrl: (NSString *) candidate {
NSString *urlRegEx=
@"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
return [urlTest evaluateWithObject:candidate];
}
它不起作用.我认为问题在于正则表达式.
It does not function. I think the problem is with the regular expression.
推荐答案
您可以使用使用if (URL && URL.scheme && URL.host)
检查URL.
这篇关于URL验证(Objective-C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文