var validExpeMail = false; var validExpeLoc = false; //turned to true in geocoder.js var validDestMail = false; var validDestLoc = false; //turned to true in geocoder.js function validateEmail(email) { //from https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript 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,}))$/; return re.test(String(email).toLowerCase()); } $("#expeMail").change(function () { validExpeMail = validateEmail($("#expeMail").val()); checkFormValid(); }); $("#destMail").change(function () { validDestMail = validateEmail($("#destMail").val()); checkFormValid(); }); document .querySelector(".custom-file-input") .addEventListener("change", function (e) { const file = e.target.files[0]; const fileName = file.name; var nextSibling = e.target.nextElementSibling; nextSibling.innerText = fileName; const filesize = (file.size / 1024 / 1024).toFixed(4); // MB if (filesize >= 2.2) { e.target.classList.add("is-invalid"); } else { e.target.classList.remove("is-invalid"); } }); function checkFormValid() { if (validExpeMail && validExpeLoc && validDestMail && validDestLoc) { $("#sendNewPlane").prop("disabled", false); } }