I have a form that uses Javascript validation in ASP.NET MVC 5. They do not want the whole form redesigned, but they want to add Javascript email validation.
I found this article:
https://www.w3resource.com/javascript/form/email-validation.php
I was excited to find something already made, so I added this Javascript to my form:
function ValidateEmail(element)
{
var email = element.value;
var mailformat = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
var labelValue = GetLabel(element);
if (email.match(mailformat))
{
return (true)
}
alert("You have entered an invalid email address!")
element.focus();
return (false)
}
But, when I try to display the page, I get an error:
Parser Error Message: “” is not valid at the start of a code block. Only identifiers, keywords, comments, “(” and “{” are valid.
How do I get this Javascript to work in my ASP.NET MVC 5 form?