JS validate input input box (letters numbers symbols Chinese)
- 2021-08-05 08:51:26
- OfStack
Enter English only
<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">
Enter English only
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')"
onkeydown="fncKeyStop(event)" onpaste="return false"
oncontextmenu="return false" />
Unable to paste, right-click will not pop up the paste menu
Only numbers can be entered:
<input onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')">
You can only enter numbers, decimal points:
<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\.]/g,'')">
Only numbers, decimal points and underscores can be entered:
<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\._]/g,'')">
Enter only English and numbers:
<input onkeyup="value=value.replace(/[\W]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
Only Chinese characters can be entered:
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
Prohibit input method input:
<input type="text" style="ime-mode: disabled">
Unable to switch input method
You can only enter Chinese, English, numbers, @ symbol and. symbol:
<input type="text"
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')">
Cannot be empty:
<input onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert('不能为空!')">