I've some regular expressions for the form fields validation.
I've an unit test to define the expected result
NSArray *suiteWebs = [NSArray arrayWithObjects:
@"http://webapp.stackoverflow.net",
@"http://webapp.stackoverflow.net/info.php",
@"http://www.stackoverflow.net",
@"http://www.stackoverflow.net/",
@"https://webapp.stackoverflow.net",
@"https://webapp.stackoverflow.net/info.php",
@"https://www.stackoverflow.net",
@"https://www.stackoverflow.net/"
@"webapp.stackoverflow.net",
@"webapp.stackoverflow.net/info.php",
@"www.stackoverflow.net",
@"www.stackoverflow.net/",
@"www.stack-overflow.com",
@"www.stackoverflow_.com",
@"www.stackover_flow.com",
nil];
NSArray *falseSuiteWebs = [NSArray arrayWithObjects:
@"ftp://webapp.stackoverflow.net",
@"http:/www.stackoverflow.net",
@"ftps://webapp.stackoverflow.net",
@"https:/www.stackoverflow.net",
nil];
for (NSString *web in suiteWebs) {
NSLog(@"Validating web %@", web);
STAssertTrue([TSAddEntityForm validateWeb:web withPatter:currentRegex], [NSString stringWithFormat:@"currentRegex web %@", web]);
}
for (NSString *web in falseSuiteWebs) {
NSLog(@"Validating web %@", web);
STAssertFalse([TSAddEntityForm validateWeb:web withPatter:currentRegex], [NSString stringWithFormat:@"currentRegex web %@", web]);
}
My actual regular expression is the next one:
NSString *webRegex4 = @"((http|https)://){0,1}((\\w)*|([0-9]*)|([\\-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([\\-|_])*))+";
My problem are with the domains with - my regular expression don't validate it. For example the url www.stack-overflow.com is rejected
Any suggestions?
Thank you