Home > DeveloperSection > Forums > Email address validation in C# MVC 4 application: with or without using Regex
john rob

Total Post:108

Points:756
Posted on    December-01-2014 10:00 PM

 ASP.Net C#  Validation  Regex 
Ratings:


 1 Reply(s)
 612  View(s)
Rate this:

I have an MVC 4 web application and I need to enter and validate some email addresses, without sending an email to the user's email address.

 

Currently I am using basic regex email validation with this pattern:

 

[RegularExpression(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z",

        ErrorMessage = "Please enter correct email address")]

Although this is validating email addresses, it passes 1@1.1 as a valid email address. For the moment I have a validation that requires symbols @ symbols . symbols where the symbols can be numeric/alphabetic and ._- .

 

I need more standard email validation for my MVC 4 application. How do I do that?



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    December-02-2014 6:33 AM

You need a regular expression for this. Look here. If you are using .net Framework4.5 then you can also use this. As it is built in .net Framework 4.5. Example

 

[EmailAddress(ErrorMessage = "Invalid Email Address")]

public string Email { get; set; }


Don't want to miss updates? Please click the below button!

Follow MindStick