如何使用Asp.net验证电子邮件ID [英] How to Validate the Email id Using Asp.net
本文介绍了如何使用Asp.net验证电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们;
我有小问题.im用( - )验证电子邮件ID。
我的代码不工作< br $>
我的代码如下:
if (!string.IsNullOrEmpty(txtEmailID.Text.Trim()))
{
// 使用正则表达式进行电子邮件验证
// string pattern = @^ [AZ] [AZ | 0-9 |] *([_] [AZ | 0-9] +)*([AZ | 0-9] [。] +([_] [AZ | 0- 9] +)*)*([] [AZ |。0-9] +([_] [AZ | 0-9] +)*)@ [AZ?| 0-9 |] * [AZ | 0- 9 |] [az | 0-9 |] * \。([az]+
// @[az | 0-9] *(\。[az] [az | 0-9] *)?)$;
string pattern = @ / ^([\w - ] +(?: \ [\w - ] +)。*)@((?:[\w - ] + \)* \w [ \w - ] {0,66})\([AZ] {2,6-}(?: \ [AZ] {2}。))$ / I跨度>?;
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(txtEmailID.Text.Trim(),pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase );
if (!match.Success)
{
MessageBox.Show( 请输入有效的电子邮件ID,Common.MSGBOX_TITLE,MessageBoxButtons.OK,MessageBoxIcon.Warning);
txtEmailID.Focus();
return false ;
}
}
Plz帮助我
问候
sathya。
解决方案
;
string pattern = < span class =code-string> @ / ^([\w - ] +(?:\。[\ w - ] +)* )@((?:[\w - ] + \)。* \w [\w - ] {0,66})\([AZ] {2,6-}(?: \ 。[az] {2})?)
/ i;
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(txtEmailID.Text.Trim(),pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (!match.Success)
{
MessageBox.Show( 请输入有效的电子邮件ID ,Common.MSGBOX_TITLE,MessageBoxButtons .OK,MessageBoxIcon.Warning);
txtEmailID.Focus();
return false ;
}
}
Plz帮助我
问候
sathya。
尝试以下模式。
string strPattern = @\ W +([ - +] \w +)* @ \w +([ - ] \w +)* \.\w +([ - ] \w +)*;
Hi Friends;
I have Small Problem .i m Validate the Email id with (-).
my code Not working
My Code below :
if (!string.IsNullOrEmpty(txtEmailID.Text.Trim()))
{
// Email Validation using regular expressions
//string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z|0-9|]*[a-z|0-9|][a-z|0-9|]*\.([a-z]" +
// @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
string pattern = @"/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i";
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(txtEmailID.Text.Trim(), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (!match.Success)
{
MessageBox.Show("Please enter a valid Email ID", Common.MSGBOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtEmailID.Focus();
return false;
}
}
Plz help Me
Regards
sathya.
解决方案
"; string pattern = @"/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)
/i"; System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(txtEmailID.Text.Trim(), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (!match.Success) { MessageBox.Show("Please enter a valid Email ID", Common.MSGBOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtEmailID.Focus(); return false; } }
Plz help Me
Regards
sathya.
try the below pattern.
string strPattern = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
这篇关于如何使用Asp.net验证电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文