如何在iPhone上验证网址 [英] How to validate an url on the iPhone

查看:204
本文介绍了如何在iPhone上验证网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的iPhone应用中,有一个设置,您可以输入网址,因为形式&功能此URL需要在线和离线验证。

In an iPhone app I am developing, there is a setting in which you can enter a URL, because of form & function this URL needs to be validated online as well as offline.

到目前为止,我还没有找到任何验证网址的方法,所以问题是;

So far I haven't been able to find any method to validate the url, so the question is;

如何在线和离线验证iPhone(Objective-C)上的URL输入?

How do I validate an URL input on the iPhone (Objective-C) online as well as offline?

推荐答案

感谢发布,您可以避免使用RegexKit。
这是我的解决方案(适用于iOS> 3.0的iphone开发):

Thanks to this post, you can avoid using RegexKit. Here is my solution (works for iphone development with iOS > 3.0) :

- (BOOL) validateUrl: (NSString *) candidate {
    NSString *urlRegEx =
    @"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
    NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx]; 
    return [urlTest evaluateWithObject:candidate];
}

这篇关于如何在iPhone上验证网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆