Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2012 19:16
Show Gist options
  • Save anonymous/4298305 to your computer and use it in GitHub Desktop.
Save anonymous/4298305 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