Hi hnmahant,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string email)
{
return View();
}
}
View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
<script type="text/javascript">
function ValidateEmail(email) {
var regx = /^\w+([-+.']\w+)*@blah.in$/;
if (!regx.test(email)) {
alert("Invalid email address.");
}
};
</script>
</head>
<body>
<div>
<% using (Html.BeginForm("Index", "Home", FormMethod.Post))
{ %>
<input type="text" name="email" value="" id="txtEmail" onchange="ValidateEmail(this.value);" />
<input type="submit" value="Submit" />
<% } %>
</div>
</body>
</html>
Screenshot