skip to Main Content
var a=document.getElementById("email").value;
var check=/[A-za-z]{3}@gmail.comb/i;
console.log(check.test(a),"true",a,check)
if(check.test(a)==true)
{
    alert("correct")
}
else if(check.test(a)==false){
    alert('false')
}

The program currently provides correct validation for email addresses in the format [email protected] and [email protected]. However, it returns false for the input [email protected]. The desired adjustment is to exclusively validate and accept the format [email protected] while maintaining the current

2

Answers


  1. Here you have two REGEX approaches that state they follow RFC2822 Email Validation standards.

    https://regex101.com/r/DPiLbv/1

    https://regexr.com/2rhq7

    You could use some lists of e-mails to test it, as was asked here:

    list of email addresses that can be used to test a javascript validation script

    Login or Signup to reply.
  2. Your validation code doesn’t work because email validation is quite difficult, and many edge cases must be covered.

    You should use the regular expression below, which is the RFC 5322 Official Standard:

    /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/
    

    (js version)
    Source: https://emailregex.com/

    Here is example code:

    function validateEmail(input) {
        var regexpr = /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/
        if (input.value.match(regexpr)) {
            console.log("Valid email address");
            return true
        } else {
            console.log("Invalid email address");
            return false;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search