Problem in email validation
I have used regular expression in email field validation . But after i used se开发者_如何学运维ssion and authentication in my website,none of the regular expression is working for me.
Can anybody help me out of this???
try this code under regularexpression validator control of asp.net----> ^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+).(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$
Hard to answer your question with no code.
But personally I would not use a regex to validate an email address. See this question
I like this method:
protected void emailValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
var a = new MailAddress(txtEmail.Text);
}
catch (Exception ex)
{
args.IsValid = false;
emailValidator.ErrorMessage = "email: " + ex.Message;
}
}
This might also be educational: I Knew How To Validate An Email Address Until I Read The RFC
The best validation method is to send a confirmation email.
This article is a good intro on why:
http://www.regular-expressions.info/email.html
And if you really want an RFC2822 regexp, here it is:
(?:[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?|[(?:(?: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])+)])
精彩评论