I'm working on a project that uses jQuery UI, along with a few other libraries. I'm trying to do input validation (after onChange event) and it's not working correctly. I have several ASP.NET MVC TextBox's and I've tried accessing them by class, and a few other ways, but they're not working.
<%=Html.TextBox("Name1", Model.Customer.FirstName, new { style = "width:200px", @class="alphaOnly", onchange = "InputValidation();" })%>
This bit of code does work, but I'd have to repeat the last 3 lines several times (~20), which is no good. Any ideas on what the problem could be?
function InputValidation() {
var className = $('.alphaOnly').attr('class');
var regexAlpha = new RegExp('[^[a-zA-Z]+$');
var value = $("#Name1").val();
value = value.replace(regexAlpha, '');
$("#Name1").val(value);
I've tried several methods to get the ID dynamically and to loop through all the controls with the "alphaOnly" class, but still to no avail.