Mac URL Validation Problem!

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
hello guys,

i am trying to validate URL with this method:

Code:
- (BOOL) validateUrl: (NSString *) candidate {
	
	NSString *urlRegEx=
	@"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
    
	NSPredicate *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx]; 
    return [urlTest evaluateWithObject:candidate];
	
}
it does not function! i think problem is with Regular expression !
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Because Objective-C doesn't have special syntax for writing regular expressions, but instead reuses the general string syntax, for every backslash in a regular expression you need to write two backslashes in the string.

You haven't done that, at least not in the character class at the end of the regex.
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
Because Objective-C doesn't have special syntax for writing regular expressions, but instead reuses the general string syntax, for every backslash in a regular expression you need to write two backslashes in the string.

You haven't done that, at least not in the character class at the end of the regex.
Code:
((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\\\\\))+[\w\d:#@%/;$()~_?\\+-=\\\\\\.&]*)
i am using this now according to what you said, but still it does not work!
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Code:
((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\\\\\))+[\w\d:#@%/;$()~_?\\+-=\\\\\\.&]*)
i am using this now according to what you said, but still it does not work!
And what about \w and \d? These need to be \\w and \\d.

BTW I haven't actually been through your regex to see if it's actually correct for not. I'd just noticed these "syntax" errors.
 

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
And what about \w and \d? These need to be \\w and \\d.

BTW I haven't actually been through your regex to see if it's actually correct for not. I'd just noticed these "syntax" errors.
thank you my friend :) it already works :apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.