Amol
Amol

Reputation: 1461

MVC3 regular expression for email

I am using the follwoing regular expression for email validation

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

Bit it accepts [][email protected][][] as a valid email.whats the pattern i should use? Is it possible to check that at client side?

Upvotes: 0

Views: 2210

Answers (1)

Anirudha
Anirudha

Reputation: 32807

If you want to validate an Email Address Regex is not the right choice.

Use MailAddress as recommended by SLaks

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

But if you are addicted to regex..just do this

.*@.*

Upvotes: 2

Related Questions