jsp表单验证汇总
js验证表单大全js验证radio是否选择 <script language="javascript">function checkform(obj){for(i=0;i<obj.oo.length;i++) if(obj.oo[i].checked==true) return true; alert("请选择")return false; }</script><form id="form1" name="form1" method="post" action="" onsubmit="return checkform(this)"> <input type="radio" name="oo" value="radiobutton" /> <input type="radio" name="oo" value="radiobutton" /> <input type="submit" name="Submit" value="提交" /></form> 1. 长度限制<script>function test() {if(document.a.b.value.length>50){alert("不能超过50个字符!");document.a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea><input type="submit" name="Submit" value="check"></form> 2. 只能是汉字 <input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">3." 只能是英文<script language=javascript>function onlyEng(){if(!(event.keyCode>=65&&event.keyCode<=90))event.returnvalue=false;}</script><input onkeydown="onlyEng();">4. 只能是数字<script language=javascript>function onlyNum(){if(!((event.keyCode>=48&&event.keyCode<=57) (event.keyCode>=96&&event.keyCode<=105)))//考虑小键盘上的数字键event.returnvalue=false;}</script><input onkeydown="onlyNum();">5. 只能是英文字符和数字<input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">6. 验证油箱格式<SCRIPT LANGUAGE=javascript RUNAT=Server>function isEmail(strEmail) {if (strEmail.search(/^\w+((-\w+) (\.\w+))*\@[A-Za-z0-9]+((\. -)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)return true;elsealert("oh");}</SCRIPT><input type=text onblur=isEmail(this.value)>7. 屏蔽关键字(这里屏蔽***和****)<script language="javascript1.2">function test() {if((a.b.value.indexOf ("***") == 0) (a.b.value.indexOf ("****") == 0)){alert("");a.b.focus();return false;}}</script><form name=a onsubmit="return test()"><input type=text name=b><input type="submit" name="Submit" value="check"></form>8. 两次输入密码是否相同<FORM METHOD=POST ACTION=""><input type="password" id="input1"><input type="password" id="input2"><input type="button" value="test" onclick="check()"></FORM><script>function check(){ with(document.all){if(input1.value!=input2.value){alert("false")input1.value = "";input2.value = "";}else document.forms[0].submit();}}</script>够了吧 屏蔽右键 很酷 oncontextmenu="return false" ondragstart="return false" onselectstart="return false"加在body中二2.1 表单项不能为空<script language="javascript"><!--function CheckForm(){ if (document.form.name.value.length == 0) { alert("请输入您姓名!");document.form.name.focus();return false;}return true;}--></script>
- zhj5282014-09-16很好,省了很多事
- 蓝加仑2013-11-23新手必备,很多,很使用
- rainning_jia1232015-11-02新手必备,很多,很使用
- JavaRoad82014-08-15初学时,很有用
- dotajava2012-05-17很好的js验证
- 粉丝: 11
- 资源: 68
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 高等数学第一章第二节数列的极限
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析