views:

70

answers:

4

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@@@[email protected]

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.

+1  A: 

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.

elusive
+4  A: 

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

try {
    address = new MailAddress(address).Address;
} catch(FormatException) {
    //address is invalid
}
Vinzz
+1 Now that's an idea!
Bobby
Though I'd say only if you're using .Net 4, I'm fairly sure earlier versions would fail on various types of valid email addresses.
ho1
I beg your pardon, but this snippet of code is OK since .NET 2 One has to catch the exception, though. [ http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx ]
Vinzz
A: 

^([\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})(]?)$

Byron Cobb