Hi. I am trying to add an error class to an input textbox to show a user that their input is invalid.
In the change event I am getting a reference to, what I presume is the input field and storing it in a variable.
Calling addClass on the variable does not work as expected. I have firebugged the code and $textBox is the correct textbox so I am not sure what I am missing here. I have many inputs that have the class "edit-budget-local" so I need to target the changed textbox. Thanks.
$("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");
}
});