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
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
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:
(js version)
Source: https://emailregex.com/
Here is example code: