I have created a function that checks to see if a input text field is valid and then either append a class name to the element that will correspond to some css code or do nothing if it is valid.
function checkInputText(inputType, elem, oldClass, classError) {
var inputT = document.getElementById(elem);
var oldClass = oldClass;
var b = regex[inputType].test(inputT.value)
if (!b) {
inputT.className = classError + ' ' + oldClass;
return false;
} else {
inputT.className = oldClass;
}
}
However, for some unknown reason, when the function calls the .test() function it returns true for an event the first time, but when you try it again it returns false.
The full code is here http://jsfiddle.net/assuredlonewolf/cscyB/2/