js/input/input box can only input Chinese characters/numbers/English

The input box can only input Chinese characters/numbers/English,
you need to pick it up by yourself, just throw it in the input,

1. The input box can only input Chinese characters

onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"

2. The input box can only enter numbers

onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"

3. The input box retains two decimal places

onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false"

4. The input box retains two decimal places and can only enter numbers and decimal points

onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"
					   onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false"

5. Only English letters and numbers can be entered

onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"

6. Only numbers and English can be entered

onKeyUp="value=value.replace(/[^\d|chun]/g,'')"

Guess you like

Origin blog.csdn.net/qq_16843563/article/details/122632433