Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for url in iPhone

I am using a regular expression to validate a website address. But it is not working because its format is not correct in iPhone. Its logic is almost correct. Can anyone rebuild this regular expression for me in iPhone ?

(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)
like image 471
Subin Kurian Avatar asked Feb 13 '26 23:02

Subin Kurian


2 Answers

Check out this one

NSString *urlRegEx =
@"(http|https)://((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+";
like image 141
Hiren Avatar answered Feb 15 '26 12:02

Hiren


use this bellow method

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

hope this help you...

:)

like image 40
Paras Joshi Avatar answered Feb 15 '26 14:02

Paras Joshi