-
-
Save sprhawk/4298321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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