my code not working on chrome mobile but all browser working

mukesh singh March 2, 2020


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<input id="ItemName" type="text" />
<script>
$('#ItemName').keypress(function (e) {
var txt = String.fromCharCode(e.which);
if (txt.match(/[>&.&<>/]/)) {
return false;
}
});
</script>

2 answers

2 accepted

0 votes
Answer accepted
enindu October 14, 2020

Use "keydown" instead of "keypress"

0 votes
Answer accepted
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2020

@mukesh singh  Welcome to the community!

Although this is not right space. But still let me help you.

There certainly some issue with 'keypress' event on Android browser (i.e. chrome mobile). Try replacing it with 'keydown' event, this usually works fine.

Suggest an answer

Log in or Sign up to answer