public ActionResult ShareEvent() { string shareEmailAddr = Request.Form["emailAddr"]; // Email Regex. string emailRegex = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$"; if (new Regex(emailRegex, RegexOptions.IgnoreCase).IsMatch(shareEmailAddr)) { int eventId; // Parse id from form. bool idParseSucceed = Int32.TryParse(Request.Form["eventId"], out eventId); if (idParseSucceed) { // Initialize email share helper var shareHelper = new EmailServices(); shareHelper.ShareByEmail(shareEmailAddr, eventId); Response.StatusCode = 200; return(Json("success")); } // Bad request if event id is not an integer. Response.StatusCode = 400; return(Json("event parse error")); } else { // Bad request if email does not match pattern. Response.StatusCode = 400; return(Json("Email address does not match the pattern")); } }