I am trying to validate a URL with this method:
Code:
- (BOOL) validateUrl: (NSString *) candidate {
NSString *urlRegEx=
@\"((https?|ftp|gop
Try with this..
- (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];
}
it may help u out.
NSURL * url = [NSURL URLWithString:@"http://www.google.com"];
BOOL isValid = [UIApplication.sharedApplication canOpenURL:url];
You can use + (id)URLWithString:(NSString *)URLString method of NSURL
, which returns nil
if the string is malformed.
Use if (URL && URL.scheme && URL.host)
for checking URL.
NSString *urlRegEx = @"http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";