Skip to content

Instantly share code, notes, and snippets.

@sprhawk
Forked from anonymous/gist:4298305
Created December 15, 2012 19:18
Show Gist options
  • Save sprhawk/4298321 to your computer and use it in GitHub Desktop.
Save sprhawk/4298321 to your computer and use it in GitHub Desktop.
NSArray * strings = [text componentsSeparatedByString:@"@"];
if([strings count] == 2) {
NSString * string = [strings objectAtIndex:0];
NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.-"];
set = [set invertedSet];
if ([string length]) { //@之前不是空字串
range = [string rangeOfCharacterFromSet:set];
if (NSNotFound == range.location) { //只包含合法字符
string = [strings objectAtIndex:1];
if ([string length]) { //@之后不是空字串
range = [string rangeOfCharacterFromSet:set];
if (NSNotFound == range.location) {//不包含非法字符
strings = [string componentsSeparatedByString:@"."];
if ([strings count] >= 2 && [[strings objectAtIndex:1] length]) { //至少有一级域名
[self.navigationItem setRightBarButtonItem:self.registerBarButtonItem animated:YES];
return ;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment