// -------------------------------------------------- // PATTERN VALIDATION FOR ALL INPUTS (global) // NOTE: this runs only for input fields (not select/textarea) // -------------------------------------------------- var inputFields = document.theform.getElementsByTagName("input"); for (var k = 0; k < inputFields.length; k++) { var myField = inputFields[k]; myField.onchange = function(){ // If input has built-in validation (email/url/number/min/max/pattern/etc.) // But skip password because your HTML uses type="email" for it if (this.id == "mypassword") { return; } if (!(this.checkValidity())) { myError.textContent = "Input does not match expected pattern: " + (this.placeholder || ""); } else { myError.textContent = ""; } }; }