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){ var fileName = document.getElementById("attachmentPlane").files[0].name; var nextSibling = e.target.nextElementSibling nextSibling.innerText = fileName }) function checkFormValid(){ if(validExpeMail && validExpeLoc && validDestMail && validDestLoc){ $('#sendNewPlane').prop("disabled", false) } }