in my iphone app users can enter a specific ip-address/URL to connect to their own server and i'm trying to check the validity of the entered address. So if a user entered something like "1234" the app would throw an error because it does not "look" like an ip-address or a URL. Right now i'm trying to accomplish this by using the following method:
- (BOOL)urlIsValid:(NSString *)address {
NSString *urlRegEx = @"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
return [urlTest evaluateWithObject:address];
}
And it I thought it was working just fine but now apparently even if I enter a correct ip-address the method will return "NO". Any ideas on what could be wrong? Thanks in advance!
I merely assumed that you wanted to check the existence of a server – Lelouch Lamperouge Mar 17 '11 at 23:15
1) Check format of the _entered_ ip address. [Are you the same Chris?][1]
2) Existence of the server. This is already answered
[1]: http://stackoverflow.com/questions/5154545/iphone-sdk-how-to-check-if-ip-entered-by-user-is-valid – Lelouch Lamperouge Mar 17 '11 at 23:45