restrict a character to type in a text box

前端 未结 5 634
借酒劲吻你
借酒劲吻你 2020-12-10 06:23

how we can restrict a character to type in a text box.

5条回答
  •  爱一瞬间的悲伤
    2020-12-10 06:59

    If you have the text box then you have to handle the onkeypress event

    
    

    You can use the following function to restrict the users

        function keypresshandler(event)
        {
             var charCode = event.keyCode;
             //Non-numeric character range
             if (charCode > 31 && (charCode < 48 || charCode > 57))
             return false;
        }
    

提交回复
热议问题