addEvent(fld, "blur", validator.checkField);
}
validator.checkForErrors();
},
checkField: function(e) {
...
// finally, disable or enable the submit button as appropriate
validator.checkForErrors();
},
checkForErrors: function() {
// Look for span.error in the page
var spans = document.getElementsByTagName('span');
for (var i=0; i
// does this span have class=error?
if (spans[i].className.match(/\berror\b/)) {
// disable the submit button and exit
document.getElementById("submitButton").disabled = true;
return;
}
}
// there were no span.error elements, so enable the submit button
document.getElementById("submitButton").disabled = false;
},
addEvent: function( obj, type, fn ) {
...
}
}
A simple PHP form using regular expressions for validation