ホームページ >ウェブフロントエンド >jsチュートリアル >jsを使って検証用に数字や文字などしか入力できないことを判定する方法の解析(まとめ)_javascriptスキル
JS判断只能是数字和小数点
0.不能输入中文
1)
2)<script><br>function chkIt(frm){<br>if (frm.n1.value.length>0&&frm.n1.value.match(/[\x01-\xFF]*/)==false){<br>alert(‘n1不能输入中文!')<br>frm.n1.focus();<br>return false;<br>}<br>}<br></script>
1.文本框只能输入数字代码(小数点也不能输入)
2.只能输入数字,能输小数点.
3.数字和小数点方法二
4.只能输入字母和汉字
5.只能输入英文字母和数字,不能输入中文
6.只能输入数字和英文chun
7.小数点后只能有最多两位(数字,中文都可输入),不能输入字母和运算符号:
57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false”>
8.小数点后只能有最多两位(数字,字母,中文都可输入),可以输入运算符号:
禁止特殊字符:
onKeyPress=”if(event.keyCode < 45 || event.keyCode > 57 ) event.returnValue = false;”
只能输入汉字:
style=”ime-mode:disabled”禁止汉字输入法
只能输入数字:
只能输入英文和数字:
控制输入框只能输入文字或数字,也可以不允许输入特殊字符
这里不允许输入如下字符: (像 ^&* 等)
不允许输入特殊字符和空格:
————————————————————————————————————————
不能为空
判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
/^([a-zA-z_]{1})([\w]*)$/g.test(str)
只能输入数字
只能输入中文
只能输入英文
——————————————————————————————————————–
1.文本框只能输入数字代码(小数点也不能输入)
2.只能输入数字,能输小数点.
3.数字和小数点方法二
4.只能输入字母和汉字
5.只能输入英文字母和数字,不能输入中文
6.只能输入数字和英文chun
7.小数点后只能有最多两位(数字,中文都可输入),不能输入字母和运算符号:
57) && event.keyCode!=46 || //./d/d$/.test(value))event.returnValue=false”>
8.小数点后只能有最多两位(数字,字母,中文都可输入),可以输入运算符号:
只能输入中文、英文、数字、@符号和.符号
只允许输入英文,且不能粘贴也无法弹出粘贴菜单
只能输入数字和点号(注意:在[^\d\.]里的d不能写成大写D,否则就变成除了数字以外的所有字符)
总而言之:先在里输入onkeyup=”value=value.replace(/[^\X]/g,”)” 然后在(/[\X]/g,”)里的X换成你想输入的代码就可以了
中文:u4E00-u9FA5
数字:d、0-9
英文:a-z、A-Z
其它符号@,点或其它符号.也可以多个,用隔开就行了.
例如:
中、英文和数字加@符号加点符号:a-\z\A-\Z0-9\u4E00-\u9FA5\@\.
若 想在文本框里不能右键弹出菜单和不能粘贴进复制的信息的话就要在里输入 onKeyDown=”fncKeyStop(event)” onpaste=”return false” oncontextmenu=”return false;”
—————————————————————————————————————————————
其一,只允许输入数字和小数点。
Second, the judgment is more detailed, and even 22..2 can be judged without counting it as a number
<script><br>function check(){<br>if (isNaN(tt.value))<br>{alert("Illegal character!");<br>tt.value=””; }<br>}<br></script>
Third, only integers are allowed. In fact, it is entirely possible to make some restrictions by drawing inferences based on Article 3.
Conclusion, in fact
style=”ime-mode:Disabled
This sentence is more practical. It means to turn off the input method. This saves some people from having to open the full-width input method to input numbers, but the result is that the input cannot come in and come to you to cry and wipe away tears. It’s your fault for poor design.
Only numbers are allowed
Only English letters, numbers and underscores are allowed to be entered (the following two methods are available)
Second, the judgment is more detailed, and even 22..2 can be judged without counting it as a number
<script><br>function check(){<br>if (isNaN(tt.value))<br>{alert("Illegal character!");<br>tt.value=””; }<br>}<br></script>
Third, only integers are allowed. In fact, it is entirely possible to make some restrictions by drawing inferences based on Article 3.
Conclusion, in fact
style=”ime-mode:Disabled
This sentence is more practical. It means to turn off the input method. This saves some people from having to open the full-width input method to input numbers, but the result is that the input cannot come in and come to you to cry and wipe away tears. It’s your fault for poor design.
Only numbers are allowed
Only English letters, numbers and underscores are allowed to be entered (the following two methods are available)
< ;input name=”username” type=”text” onkeyup=”value=value.replace(/[^/w/.//]/ig,”)”>
Only English letters, numbers and &=@
Only Chinese characters are allowed to be entered
me” type=”text” style=”ime-mode:disabled”>
Only English letters, numbers and &=@
Only Chinese characters are allowed to be entered