I have below code and currently it bypasses the 'return false' expression when i enter incorrect format of email address. Any idea please.
index.html
<form class="text-muted first"
action="javascript:;"
method="POST"
id="contactform"
name="form1"
onsubmit="ajaxRequest(); return false">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name"
required placeholder="Ahmed">
</div>
<div class="form-group">
<label for="email" class="mt-2">Email</label>
<input type="text" class="form-control" id="email" name="emailaddr"
required placeholder="john@email.com">
</div>
<button class="btn btn-outline-warning p-2 mt-2" type="submit"
onclick="ValidateEmail(document.form1.emailaddr)">Submit Question</button>
</form>
JavaScript
$(document).ready(function() {
$('.nav-button').click(function() {
$('.nav-button').toggleClass('change');
});
$(window).scroll(function() {
let position = $(this).scrollTop();
if (position >= 200) {
$('.nav-menu').addClass('custom-navbar');
} else {
$('.nav-menu').removeClass('custom-navbar');
}
});
});
function ValidateEmail(inputText) {
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (inputText.value.match(mailformat)) {
alert('Email Sent!');
return true;
} else {
return false;
}
}
function ajaxRequest(e) {
$.get('mail.php', function(data) {
// $(".result").html(data);
// alert("Load was performed.");
$('.contactform').hide();
$('.confirmation').show();
});
}