TransWikia.com

function not getting called onkeypress event of the input element

SharePoint Asked by Nidhi Maheshwari on January 3, 2021

I am trying to allow only numeric input in a textbox…For this I am writing a code as follows:

'<input type="text" id="txtFlexibility" class="form-control input-sm" onkeypress="return isNumberKey(event)" />'

protected isNumberKey(event): boolean{
const charCode = (event.which) ? event.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;
return true;}

isNumberKey(event) is not getting called….
Please suggest an workaround….

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP