Disallow input special characters with limited characters in jQuery
<textarea name="my_description" class="my-description"></textarea>
I want to set restriction for special character and also set character limit for my HTML input using jQuery. How can I set disallow input special characters and set limit characters using jQuery, while entering character in input.
If you want to disallow special characters and also set a character limit for your HTML input, apply this code in your jquery
$('body').on('keyup, input',"#inputID",function(){ if (this.value.match(/[^a-zA-Z0-9 ]/g)) { this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, ''); } var _msgLenght = $(this).val().length; if (_msgLenght > 30) { $(this).val($(this).val().substring(0, 30)); } });
Question and answer is powered by AnsPress.io