iphone开发:邮箱有效验证
判断是不是一个有效的邮箱地址。
-(BOOL)is_email_can_be_open:(NSString*)email
{
if( (0 != [email rangeOfString:@"@"].length) && (0 != [email rangeOfString:@"."].length) )
{
NSMutableCharacterSet *invalidCharSet = [[[[NSCharacterSet alphanumericCharacterSet] invertedSet]mutableCopy]autorelease];
[invalidCharSet removeCharactersInString:@"_-"];
NSRange range1 = [email rangeOfString:@"@" options:NSCaseInsensitiveSearch];
// If username part contains any character other than "." "_" "-"
NSString *usernamePart = [email substringToIndex:range1.location];
NSArray *stringsArray1 = [usernamePart componentsSeparatedByString:@"."];
for (NSString *string in stringsArray1)
{
NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet: invalidCharSet];
if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
{
return NO;
}
}
NSString *domainPart = [email substringFromIndex:range1.location+1];
NSArray *stringsArray2 = [domainPart componentsSeparatedByString:@"."];
for (NSString *string in stringsArray2)
{
NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet:invalidCharSet];
if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
{
return NO;
}
}
return YES;
}
return NO;
}
摘自 云怀空-abel
相关新闻>>
- 发表评论
-
- 最新评论 更多>>