javascriptregexinputthai

Jquery İnput Keyup Thai,Eng and Space Chacter


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 {

}

});

Help :))


Solution

  • 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">