I am trying below code for email/password validation but form is not submitting after successful validation. Any help ?.
$("form").submit(function(e) {
e.preventDefault();
const email = $(".email").val();
const password = $(".password").val();
const re = /^(([^<>()[\]\\.,;:\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,}))$/;
console.log(re.test(String(email).toLowerCase()));
$('.email_v').text('');
$('.pass_v').text('');
if (!re.test(String(email).toLowerCase())) {
$('.email_v').text("Please provide Valid Email Address");
return false;
}
if (password.length < 6) {
$('.pass_v').text("Password must be atleast 6 characters");
return false;
}
return true;
});
e.preventDefault()prevents the form from submitting.toLowerCase()when the regexp matches both upper and lower case? And it's not necessary to callString(), since.val()always returns a string.e.preventDefault()to the places returningfalseor don't do any returns and usee.preventDefaultif validation fails at the end of your callback