script that services multiple input fields

script that services multiple input fields

Hello,

I have several input fields that only allow Alphabets & no space. I also have the code below which services that need but would have to copy / past the code for each individual field for it to work. is there a better way to use the code below and have selected input fields reference the same code



  1. $(function() { $('input[name="fname"]').bind('keypress', function (event) { var regex = new RegExp("^[a-zA-Z]+$"); var key = String.fromCharCode (!event.charCode ? event.which : event.charCode); if (!regex.test(key)) { event.preventDefault(); return false; } }); });