电子邮件身份验证

时间:2010-08-04 06:58:32

标签: iphone

嘿,任何人都可以建议我在iPhone应用程序中验证电子邮件地址有任何API或示例

2 个答案:

答案 0 :(得分:1)

您需要使用正则表达式来检查电子邮件验证。

你可以做一个简单的测试:

NSString *emailRegEx = @"(?:[a-z0-9!#$%\\&'*+/=?\\^_ {|}〜 - ] +(?:!?\ [A-Z0-9#$%\&安培;'* + / = \ ^ _ {|}" @"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" @"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-" @"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5" @"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" @"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" @"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";

NSPredicate * regExPredicate =     [NSPredicate predicateWithFormat:@“SELF MATCHES%@”,emailRegEx];

BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:myString];

剩下的唯一问题是:什么是可用于验证NSString是否包含语法上有效的电子邮件地址的正则表达式?

答案 1 :(得分:0)

试试这个..

NSString * xmlString = @“Hello”; NSURL * serviceUrl = [NSURL URLWithString:@“http://my.company.com/myservice”]; NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl]; [serviceRequest setValue:@“text / xml”forHTTPHeaderField:@“Content-type”]; [serviceRequest setHTTPMethod:@“POST”]; [serviceRequest setHTTPBody:[xmlString dataUsingEncoding:NSASCIIStringEncoding]];

NSURLResponse * serviceResponse; NSError * serviceError; serviceResponse = [NSURLConnection sendSynchronousRequest:serviceRequest returningResponse:& serviceResponse error:& serviceError];