Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I am totally new to Mvc 4. So I am creating a simple registration form.
To that form I want to apply java script validation.
While I am writing code for email validation i am getting error at @ symbol.
Can Any one help me....
This is my code..


function validateEmail()
{
var EmailVal = document.getElementById("Email").value;
var pattern =/^\w+([\.-]?\w+)@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
debugger
var temp=pattern.test(EmailVal); // returns a boolean
if(!temp)
{
alert("Invalid Email");
return false
}

}

Here I am getting error at @ symbol..in regular expression.
Posted
Updated 23-Jun-14 2:33am
v2
Comments
Sergey Alexandrovich Kryukov 23-Jun-14 16:34pm    
What does it mean, exactly, "I am getting error at @ symbol in regular expression."? How? :-)
—SA

Indeed, you regular expression does not match valid e-mail addresses, but I don't know how you could get any error on '@'. Regular expression syntax is not broken, you should have just get failures to match, not any errors. This problem of composing proper regular expression to validate e-mail is fairly simple. Many subtle moments of it are discussed here, with different variants of the solution: http://www.regular-expressions.info/email.html[^].

—SA
 
Share this answer
 
The Solution is Add another @ at @ symbol. Two @ symbols will not work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900