This article describes how to restrict the input value type of a text box in javascript. it involves javascript mouse events, keyboard buttons, and string-related operation techniques, which are of great practical value, for more information about how to restrict the input value type of a text box in javascript, see the following example. Share it with you for your reference. The specific analysis is as follows:
Requirements: only numbers and decimal places can be entered in all text boxes. Other symbols cannot be entered;
The key point is that I want to limit the number when the user inputs, instead of determining when the user submits -- that is to say, if the user enters a number or decimal point in the text box, the user can enter the number normally. if the user inputs non-numeric characters such as letters, the text box does not respond, and the entered characters are not displayed.
Script var s ="57&&event.keyCode!=190) return false\" "+ //限制只能输入数字"onblur=\"value=value.replace(/[^0-9\.]/g,'')\" " + //限制鼠标点击输入非数字"onbeforepaste=\"clipboardData.setData(\"text\"," + //限制只能粘贴数字"clipboardData.getData(\"text\").replace(/[^0-9\.]/g,''))\">";document.write(s);《script》
希望本文所述对大家的javascript程序设计有所帮助。