确保用户输入的电子邮件地址字符串格式正确吗? [英] Ensure User has entered email address string in correct format?
本文介绍了确保用户输入的电子邮件地址字符串格式正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在联系人屏幕中有一个文本字段,用户需要输入电子邮件地址来发送信息。
什么是确保用户输入有效电子邮件地址的最佳方式,如:
i have a text field in Contact screen and the user need to enter email address to send me message. Whats the best way to ensure the user has entered a valid email address such as:
a@b.com / net / org / co.il
abc@gmail.com
abc@yahoo.com
等..
谢谢
推荐答案
以下内容:
- (BOOL) validateEmail: (NSString *) candidate {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
// return 0;
return [emailTest evaluateWithObject:candidate];
}
-(IBAction)btnTapped:(id)sender{
if([self validateEmail:[txtEmail text]] ==1)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"You Enter Correct Email id." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"You Enter Incoorect Email id." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
}
这篇关于确保用户输入的电子邮件地址字符串格式正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文