Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rethish

macrumors member
Original poster
Oct 16, 2008
41
0
-(IBAction)web:(id)sender
{

NSString *web =[[NSString alloc]initWithString:[webfield stringValue]];


NSString *webRegEx = @"www.[A-Z0-9a-z._%+-]+.[a-z]{2,4}";

NSPredicate *webTest = [NSPredicate predicateWithFormat:mad:"SELF MATCHES %@",webRegEx];



if ([webTest evaluateWithObject:web] == YES)
{

[NSApp beginModalSessionForWindow:valid];
[webfield web:sender];

}

else
{
[NSApp beginModalSessionForWindow:notvalid];
[webfield setStringValue:mad:""];
[webfield web:sender];

}
}



when this code is used www.hai.com , wwwww.fff.com , wwwfghw.hai.com , these format are shown valid and also the letter 'w' can used any number of times and also other letters are also accepted .

I need a standard format ie: www.hhhh.com , the w should appear only three times otherwise it must not be valid.


How can it be poosible ? please help
thakyou
 
I need a standard format ie: www.hhhh.com , the w should appear only three times otherwise it must not be valid.


How can it be poosible ? please help
thakyou

The problem is, a site may not have a 'www' and still be valid, or it may have www1, www2, etc. so building your own check will be a mess of regexes (and it's re-inventing the wheel); even your example of "wwwfghw.hai.com" is perfectly valid. The say the easiest thing to do would be using the NSURL class to check the format. the +(id)URLWithString: method will return nil if you pass it a malformed url and non-nil if the passed string is a correctly formed url. This way you could then use the newly created class to extract out the specific information you need.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.