Jquery İnput Keyup Thai,Eng and Space Chacter

644 Views Asked by At

I want to define the input key up in English, Thai and a space character. Other characters will be deleted.

$("#username").keyup(function () {


if (this.value.match(/d/g)){


this.value = this.value.replace(/d+/g,'');


}

else {

}

});
  • Keyup: %'^%'& (delete)
  • Keyup : Jack Boo (ok)
  • Keyup : คน Boo (ok)
  • Keyup : คน%^+ (delete)
  • Keyup : คน452 (delete)

Help :))

1

There are 1 best solutions below

0
loumadev On BEST ANSWER

Use input event, so you can also filter pasted text.

$("#username").on("input", function(e) {
  $(this).val(function(i, v) {
    return v.replace(/[^a-z\u0E00-\u0E7F ]/gi, "");
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="username">