I have an app which is running on iOS8. In this app I use a UITextField, which contains a URL. I want to validate that field.
Eg: If user enters incorrect url such "abckmlo" it should not allow that input and should notify the user.
Following code:
-(BOOL) validateUrl: (NSString *)url
{
    NSString *urlRegEx =@"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
    NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
    if ([urlTest evaluateWithObject: url] == YES)
    {    
        NSLog(@"URL is valid!");    
    }
    else
    {    
        NSLog(@"URL is not valid!");    
    }
    return [urlTest evaluateWithObject:candidate];    
}
When I execute the above code it always goes into the else block. What is causing this?
 
    