I have the following jQuery shell which works:
$('.jq_noSpaces').on('change', function(){
alert('you changed the value in the box');
});
My form attributes are id="username" name="username"
How do I use the following jQuery replace function to automatically change remove the spaces from the input field?
str.replace(/\s+/g, '');
Thanks
You can use the syntax:
$(this).val($(this).val().replace(/\s+/g, ''));
Inside the event handler.
Replace content of your box in event handler
this.value = this.value.replace(/\s+/g, '');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With