开发者

Regular Expression for email validation. [duplicate]

This question 开发者_如何学编程already has answers here: Closed 12 years ago.

Possible Duplicate:

What is the best regular expression for validating email addresses?

I'm using a form which ask for email address. I used regular expression for it as

.*@.*\..*

But it is not working fine for some of my test email id like

dsrasdf@@@fer@hbdf.vjif

Any one provide me regular expression for the email validation in asp.net or can i use any other method for it.

Please give your suggestions.


Best to rely on the framework for this kind of stuff.

try {
    address = new MailAddress(address).Address;
} catch(FormatException) {
    //address is invalid
}


I am using the following regular expression for my email validations (case insensitive):

^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$

I do not know about asp, but i think that you can use it like this.


^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z{2-4}|[0-9]{1,3})(\]?)$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜