I am using this home-made function to validate text fields, but for some reason, it doesn't "accept" spaces. I find that weird, since I have \s in my class...
function validateText(controlid, minlength, maxlength, required) {
var control = document.getElementById(controlid);
if (!required && control.value.length == 0) control.style.backgroundColor = "White";
else {
var regex = new RegExp("^[a-zA-Z0-9\(\)\.\s_,:/-]{" + minlength + "," + maxlength + "}$", "g");
if (!regex.test(control.value))
control.style.backgroundColor = "#FFDDDD";
else
control.style.backgroundColor = "White";
}
}
Can you tell me why entering a space turns the textbox red? Thanks :)