I have a requirement to validate an email address entered when a user comes out from the textbox.
I have googled for this but I got form validation JScript; I don't want form validation. I want textbox validation.
I have written below JScript but "if email invalid it's not returning the same page".
function validate(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; //var address = document.getElementById[email].value; if (reg.test(email) == false) { alert('Invalid Email Address'); return (false); } }
const validateEmail = (email) => { return String(email) . toLowerCase() . match( /^(([^<>()[\]\\.,;:\s@"]+(\. [^<>()[\]\\.,;:\s@"]+)*)|(".
The best way to "validate" an email addresses is to simply have them type it twice and run a Regex check that gives a WARNING to the user that it doesn't look like a valid email address if it does not match the pattern, and asks the user to double check.
Assuming your regular expression is correct:
inside your script tags
function validateEmail(emailField){ var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (reg.test(emailField.value) == false) { alert('Invalid Email Address'); return false; } return true; }
in your textfield:
<input type="text" onblur="validateEmail(this);" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With