Home > DeveloperSection > Forums > How to use regular expression for email validation in mvc
Ankit Singh

Total Post:341

Posted on    February-26-2016 12:20 AM

 ASP.NET MVC Mvc  Data Validation 

 1 Reply(s)
 264  View(s)
Rate this:
We want to  use regular expression for email validation in mvc .
I have already used  "^[a-zA-Z0-9-.]+@[a-zA-Z0-9-.]+$"  but it is not working  with  "_"  characters .
How we will do this Please help me.

aditya kumar Patel

Total Post:250

Posted on    February-26-2016 12:22 AM

If you are using pattern "^[a-zA-Z0-9-.]+@[a-zA-Z0-9-.]+$" please

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

it will work properly.


@model ForumMVC.Models.Customer


ViewBag.Title = "CheckRegularExpression";


<script src="~/Scripts/jquery-2.1.4.js"></script>

<script src="~/Scripts/jquery.validate.min.js"></script>

<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>


@using (Html.BeginForm())


@Html.LabelFor(m => m.EmailId)

@Html.TextBoxFor(m => m.EmailId)

@Html.ValidationMessageFor(m => m.EmailId)


using System;

using System.Collections.Generic;

using System.Linq;

using System.Linq.Expressions;

using System.Web;

using System.ComponentModel.DataAnnotations;

namespace ForumMVC.Models


public class Customer



ErrorMessage = "Please enter a valid e-mail-2 adress")]

public string EmailId








Modified On Feb-26-2016 12:32:34 AM

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

Follow MindStick