Reputation:
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.
Upvotes: 0
Views: 68
Reputation: 518
function ValidateEmail(element) {
var email = element.value;
var mailformat = /^\w+([\.-]?\w+)*@@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (email.match(mailformat)) {
return true;
}
alert("You have entered an invalid email address!");
element.focus();
return false;
}
Try this, I have escaped the single @
, there can be parsing issues with it.
Upvotes: 1