The JavaScript restriction text box input content code shared with you is as follows
<style type="text/css"> <!-- .STYLE1 { color: #0099FF; font-weight: bold; font-size: x-large; } --> </style> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p align="center" class="STYLE1">亲,试试效果吧!</p> <p align="center"><strong>请输入数字或字母</strong>: <input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"> </p> <p align="center"><strong>请输入数字,只能输入数字哦</strong>: <input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"> </p> <p align="center"><strong>请输入汉字,只能输入汉字哦</strong>: <input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"> </p>
Operation rendering:
Let me add some more for you:
There can only be up to two digits after the decimal point (both numbers and Chinese characters can be entered). Letters and arithmetic symbols cannot be entered:
<input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || //./d/d$/.test(value))event.returnValue=false">
Only numeric codes can be entered in the text box (decimal points cannot be entered either)
<input onkeyup="this.value=this.value.replace(//D/g,'')" onafterpaste="this.value=this.value.replace(//D/g,'')">
In fact, you can also restrict other content, such as only letters. You can try some other things.
The above is the JavaScript restriction text box input content code shared with everyone