This tutorial teaches you how to use JavaScript to restrict input to English, or to restrict the entry of Chinese.
No English input:
Copy Code code as follows:
<input type= "text" onkeypress= "return event.keycode>=48&&event.keycode<=57| | (This.value.indexOf ('. ') <0?event.keycode==46:false) "onpaste=" Return!clipboarddata.getdata (' text '). Match (/\d/) "ondragenter=" return False ">
Only Chinese can be entered with regular expression restrictions:
Copy Code code as follows:
<input type= "text" onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')" Onbeforepaste= "Clipboarddata.setdata ( ' Text ', Clipboarddata.getdata (' text '). Replace (/[^\u4e00-\u9fa5]/g, ') "/>
1. Only full-width characters can be entered with regular expression restrictions:
Copy Code code as follows:
<input type= "text" onkeyup= "Value=value.replace (/[^\uff00-\uffff]/g, ')" Onbeforepaste= "Clipboarddata.setdata ( ' Text ', Clipboarddata.getdata (' text '). Replace (/[^\uff00-\uffff]/g, ') "/>
2. Only numbers can be entered with regular expression restrictions:
Copy Code code as follows:
<input type= "text" onkeyup= "Value=value.replace (/[^\d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "/>
3. Only numbers and English can be entered with regular expression restrictions:
Copy Code code as follows:
<input type= "text" onkeyup= "Value=value.replace (/[\w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') "/>