验证来自文本框的多封电子邮件 [英] validating multiple emails from a textbox
本文介绍了验证来自文本框的多封电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框1)CC.在这些邮件中,我必须验证多个用逗号或分号分隔的电子邮件.任何人都知道如何使用正则表达式进行验证吗?
请让我知道.
谢谢.
Mohd Wasif
Hi,
I have a textbox 1)CC . In these I have to validate emails more than one separated by comma or semicolon .Can any one know how to validate using regular expression ?
Please let me know .
Thanking you.
Mohd Wasif
推荐答案
我不知道要实现您的解决方案的特定正则表达式,但我可以向您展示一种方法.
I don''t know about specific Regex to achieve to your solution but yeah I can show you a way.
string listofEmail = "abc@xyz.com,bbc@co.uk";
//Count total no of Email in the list
int totalEmail = listofEmail.Split(',').Count();
Regex regex = new Regex(@"[A-Za-z0-9._%-]+@[a-zA-Z0-9.-]+\.[A-Za-z]{2,4}");
int regexMatch = regex.Matches(listofEmail).Count;
//Count no of email with which regex matches
if (totalEmail == regexMatch)
{
//Emails are correctly formatted
}
else
{
//Raise error on one or more email is incorrect in the list
}
公共布尔isMultipleEmail(string strEmail)
{
string [] eid = strEmail.Split('','');
for(int i = 0; i< eid.Length; i ++)
{
字符串strRegex = @"^([a-zA-Z0-9 _ \-\\.] +)@ [a-z0-9-] +(\.[a-z0-9-] +)*(\.[ az] {2,3} [] *)
public bool isMultipleEmail(string strEmail)
{
string[] eid = strEmail.Split('','');
for (int i = 0; i < eid.Length; i++)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}[ ]*)
;
正则表达式re =新正则表达式(strRegex);
如果(!(re.IsMatch(eid [i] .ToString())))
{
return(false);
}
}
return(true);
}
strEmail = textbox.text;
";
Regex re = new Regex(strRegex);
if (!(re.IsMatch(eid[i].ToString())))
{
return (false);
}
}
return (true);
}
strEmail=textbox.text;
这篇关于验证来自文本框的多封电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文