I'm attempting to give an error class to an input textbox to inform the user that their input is invalid.
Within the change event, I am referencing what seems to be the input field and storing it in a variable.
However, calling addClass on the variable is not producing the desired result. After debugging with firebug, I can confirm that $textBox corrects refers to the intended textbox, so I'm unsure of what I may be overlooking here. Since I have several inputs with the class "edit-budget-local," I need to specifically target the changed textbox. Thank you.
$("input.edit-budget-local").change(function () {
var $textBox = this;
var newValue = $textBox.value;
if (newValue.match(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/) == null) {
$textBox.addClass("error");
}
});