Wednesday, 6 February 2013

ASP .NET MVC3 : Email Address Validation

Here's the source code of email address validation in a model.cs file.
You can use this code to check if the email address is valid or not.

---------------------------------------------------------------------------------------
[RegularExpression(@"^([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})(\]?)$", ErrorMessage = "Please enter a valid e-mail adress")]
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address*")]
 public string Email { get; set; }
---------------------------------------------------------------------------------------

No comments:

Post a Comment