0

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);
}
1
  • If you are using asp.net MVC, then why don't you implement the validation using Data Annotations in Model? Commented Dec 6, 2019 at 7:41

2 Answers 2

1

Use u+0040 uni-code instead of @.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.