0

I'm validating URLs with the following method:

+ (BOOL)confirmValidUrl:(NSString *)url {

    BOOL isValidURL = NO;
    NSString *urlRegEx = @"(?:www\\.)?[\\w\\d\\-_]+\\.\\w{2,3}(\\.\\w{2})?(/(?<=/)(?:[\\w\\d\\-./_]+)?)?";
    NSPredicate *urlPredic = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx];
    isValidURL = [urlPredic evaluateWithObject:url];

    return isValidURL;
}

Now I need to mark as valid URLs the ones that have emojis like http://.la but I haven't found anything related to this, does someone know how I should modify my method to do what I'm looking for?

Thanks in advance.

Asneroll
  • 155
  • 1
  • 3
  • 10

1 Answers1

0

You Can Use this: e.x.http://www.xn--vi8hiv.ws/

+ (BOOL) urlIsValiad: (NSString *) url
{
    NSString *regex =
    @"((?:http|https)://)?(?:[A-Za-z0-9]{1,25}\\.)?[\\w\\d\\-_]+\\.\\w{2,3}(\\.\\w{2})?(/(?<=/)(?:[\\w\\d\\-./_]+)?)?";
    NSPredicate *regextest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

   if ([regextest evaluateWithObject: url] == YES) {
       NSLog(@"URL is valid!");
   } else {
       NSLog(@"URL is not valid!");
   }
   return [regextest evaluateWithObject:url];
}
Ketan Odedra
  • 1,215
  • 10
  • 35