Zaheen
Zaheen

Reputation: 11

Jquery email validation is not working in MVC

I'm using this code in mvc for email validation but after we typed @ of any text in textbox for example : abc@ after @ validation is not wokring and form is submit without validation error.

if (!isValidEmailAddress(email))
 {
    $('.error').css("display", "block");
      isValid == false
 }
 else 
{
  $('.error').css("display", "none");
}
function isValidEmailAddress(emailAddress) 
{
   var res = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return res.test(emailAddress);
}

Upvotes: 0

Views: 594

Answers (2)

Zaheen
Zaheen

Reputation: 11

I use uni code instead of @ and i made a silly mistake on my own code is i use isValid == false

Upvotes: 0

Zain Khan
Zain Khan

Reputation: 1844

Use u+0040 uni-code instead of @.

Upvotes: 1

Related Questions