406 lines
24 KiB
HTML
406 lines
24 KiB
HTML
|
||
|
||
<div id="sina_keyword_ad_area2" class="articalContent ">
|
||
<div>屏蔽右键 很酷 <wbr></div>
|
||
<div>oncontextmenu="return false" ondragstart="return false"onselectstart="return false"</div>
|
||
<div>加在body中</div>
|
||
<div><br>
|
||
</div>
|
||
<div><br>
|
||
</div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.1 <wbr> <wbr> 表单项不能为空</div>
|
||
<div><br>
|
||
</div>
|
||
<div><script <wbr> <wbr>language="javascript"></div>
|
||
<div><!--</div>
|
||
<div>function <wbr> <wbr>CheckForm()</div>
|
||
<div>{ <wbr></div>
|
||
<div>if <wbr> <wbr>(document.form.name.value.length <wbr> <wbr> == <wbr> <wbr> 0) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("请输入您姓名!");</div>
|
||
<div>document.form.name.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>--></div>
|
||
<div></script></div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.2 <wbr> <wbr> 比较两个表单项的值是否相同</div>
|
||
<div><br>
|
||
</div>
|
||
<div><script <wbr> <wbr>language="javascript"></div>
|
||
<div><!--</div>
|
||
<div>function <wbr> <wbr>CheckForm()</div>
|
||
<div>if <wbr> <wbr>(document.form.PWD.value <wbr> <wbr> != <wbr> <wbr>document.form.PWD_Again.value) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("您两次输入的密码不一样!请重新输入.");</div>
|
||
<div>document.ADDUser.PWD.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>--></div>
|
||
<div></script></div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.3 <wbr> <wbr>表单项只能为数字和"_",用于电话/银行帐号验证上,可扩展到域名注册等</div>
|
||
<div><br>
|
||
</div>
|
||
<div><script <wbr> <wbr>language="javascript"></div>
|
||
<div><!--</div>
|
||
<div>function <wbr> <wbr>isNumber(String)</div>
|
||
<div>{ <wbr></div>
|
||
<div>var <wbr> <wbr> Letters <wbr> <wbr> = <wbr> <wbr> "1234567890-"; <wbr> <wbr> //可以自己增加可输入值</div>
|
||
<div>var <wbr> <wbr> i;</div>
|
||
<div>var <wbr> <wbr> c;</div>
|
||
<div>if(String.charAt( <wbr> <wbr> 0 <wbr> <wbr> )=='-')</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>if( <wbr> <wbr> String.charAt( <wbr> <wbr> String.length <wbr> <wbr> - <wbr> <wbr> 1 <wbr> <wbr> ) <wbr> <wbr> == <wbr> <wbr> '-' <wbr> <wbr>)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>for( <wbr> <wbr> i <wbr> <wbr> = <wbr> <wbr> 0; <wbr> <wbr> i <wbr> <wbr> < <wbr> <wbr> String.length; <wbr> <wbr> i <wbr> <wbr> ++ <wbr> <wbr> )</div>
|
||
<div>{ <wbr></div>
|
||
<div>c <wbr> <wbr> = <wbr> <wbr> String.charAt( <wbr> <wbr> i <wbr> <wbr> );</div>
|
||
<div>if <wbr> <wbr> (Letters.indexOf( <wbr> <wbr> c <wbr> <wbr> ) <wbr> <wbr>< <wbr> <wbr> 0)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>function <wbr> <wbr>CheckForm()</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(! <wbr> <wbr>isNumber(document.form.TEL.value)) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("您的电话号码不合法!");</div>
|
||
<div>document.form.TEL.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>--></div>
|
||
<div></script></div>
|
||
<div><br>
|
||
</div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.4 <wbr> <wbr> 表单项输入数值/长度限定</div>
|
||
<div><br>
|
||
</div>
|
||
<div><script <wbr> <wbr>language="javascript"></div>
|
||
<div><!--</div>
|
||
<div>function <wbr> <wbr> CheckForm() <wbr></div>
|
||
<div>{ <wbr></div>
|
||
<div>if <wbr> <wbr>(document.form.count.value <wbr> <wbr>> <wbr> <wbr> 100 <wbr> <wbr> || <wbr> <wbr> document.form.count.value <wbr> <wbr> < <wbr> <wbr> 1)</div>
|
||
<div>{ <wbr></div>
|
||
<div>alert("输入数值不能小于零大于100!");</div>
|
||
<div>document.form.count.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>if <wbr> <wbr>(document.form.MESSAGE.value.length<10)</div>
|
||
<div>{ <wbr></div>
|
||
<div>alert("输入文字小于10!");</div>
|
||
<div>document.form.MESSAGE.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>//--></div>
|
||
<div></script></div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.5 <wbr> <wbr>中文/英文/数字/邮件地址合法性判断</div>
|
||
<div><br>
|
||
</div>
|
||
<div><SCRIPT <wbr> <wbr>LANGUAGE="javascript"></div>
|
||
<div><!--</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr> isEnglish(name) <wbr> <wbr> //英文值检测</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(name.length <wbr> <wbr> == <wbr> <wbr> 0)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>for(i <wbr> <wbr> = <wbr> <wbr> 0; <wbr> <wbr> i <wbr> <wbr>< <wbr> <wbr> name.length; <wbr> <wbr> i++) <wbr> <wbr> { <wbr></div>
|
||
<div>if(name.charCodeAt(i) <wbr> <wbr>> <wbr> <wbr> 128)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr> isChinese(name) <wbr> <wbr> //中文值检测</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(name.length <wbr> <wbr> == <wbr> <wbr> 0)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>for(i <wbr> <wbr> = <wbr> <wbr> 0; <wbr> <wbr> i <wbr> <wbr>< <wbr> <wbr> name.length; <wbr> <wbr> i++) <wbr> <wbr> { <wbr></div>
|
||
<div>if(name.charCodeAt(i) <wbr> <wbr>> <wbr> <wbr> 128)</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr> isMail(name) <wbr> <wbr> // <wbr> <wbr> E-mail值检测</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(! <wbr> <wbr>isEnglish(name))</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>i <wbr> <wbr> = <wbr> <wbr> name.indexOf(" <wbr> <wbr> at <wbr> <wbr>");</div>
|
||
<div>j <wbr> <wbr> = <wbr> <wbr> name <wbr> <wbr> dot <wbr> <wbr> lastIndexOf(" <wbr> <wbr> at <wbr> <wbr> ");</div>
|
||
<div>if(i <wbr> <wbr> == <wbr> <wbr> -1)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>if(i <wbr> <wbr> != <wbr> <wbr> j)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>if(i <wbr> <wbr> == <wbr> <wbr> name <wbr> <wbr> dot <wbr> <wbr>length)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr> isNumber(name) <wbr> <wbr> //数值检测</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(name.length <wbr> <wbr> == <wbr> <wbr> 0)</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>for(i <wbr> <wbr> = <wbr> <wbr> 0; <wbr> <wbr> i <wbr> <wbr>< <wbr> <wbr> name.length; <wbr> <wbr> i++) <wbr> <wbr> { <wbr></div>
|
||
<div>if(name.charAt(i) <wbr> <wbr>< <wbr> <wbr> "0" <wbr> <wbr> || <wbr> <wbr> name.charAt(i) <wbr> <wbr> > <wbr> <wbr> "9")</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr>CheckForm()</div>
|
||
<div>{ <wbr></div>
|
||
<div>if(! <wbr> <wbr>isMail(form.Email.value)) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("您的电子邮件不合法!");</div>
|
||
<div>form.Email.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>if(! <wbr> <wbr>isEnglish(form.name.value)) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("英文名不合法!");</div>
|
||
<div>form.name.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>if(! <wbr> <wbr>isChinese(form.cnname.value)) <wbr> <wbr>{ <wbr></div>
|
||
<div>alert("中文名不合法!");</div>
|
||
<div>form.cnname.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>if(! <wbr> <wbr>isNumber(form.PublicZipCode.value)) <wbr> <wbr> { <wbr></div>
|
||
<div>alert("邮政编码不合法!");</div>
|
||
<div>form.PublicZipCode.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>//--></div>
|
||
<div></SCRIPT></div>
|
||
<div><br>
|
||
</div>
|
||
<div>2.6 <wbr> <wbr> 限定表单项不能输入的字符</div>
|
||
<div><br>
|
||
</div>
|
||
<div><script <wbr> <wbr>language="javascript"></div>
|
||
<div><!--</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr>contain(str,charset)// <wbr> <wbr>字符串包含测试函数</div>
|
||
<div>{ <wbr></div>
|
||
<div>var <wbr> <wbr> i;</div>
|
||
<div>for(i=0;i<charset.length;i++)</div>
|
||
<div>if(str.indexOf(charset.charAt(i))>=0)</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
<div>function <wbr> <wbr>CheckForm()</div>
|
||
<div>{ <wbr></div>
|
||
<div>if <wbr> <wbr>((contain(document.form.NAME.value, <wbr> <wbr> "%\(\)><")) <wbr> <wbr> || <wbr> <wbr> (contain(document.form.MESSAGE.value, <wbr> <wbr>"%\(\)><")))</div>
|
||
<div>{ <wbr></div>
|
||
<div>alert("输入了非法字符");</div>
|
||
<div>document.form.NAME.focus();</div>
|
||
<div>return <wbr> <wbr> false;</div>
|
||
<div>}</div>
|
||
<div>return <wbr> <wbr> true;</div>
|
||
<div>}</div>
|
||
<div>//--></div>
|
||
<div></script> <wbr></div>
|
||
<div><br>
|
||
</div>
|
||
<div>1. 检查一段字符串是否全由数字组成 <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr> <wbr></div>
|
||
<div><scriptlanguage="Javascript"><!-- <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>function checkNum(str){return str.match(/\D/)==null} <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>alert(checkNum("1232142141")) <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>alert(checkNum("123214214a1")) <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>// --></script> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>2. 怎么判断是否是字符 <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>if (/[^\x00-\xff]/g.test(s)) alert("含有汉字"); <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>else alert("全是字符"); <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>3. 怎么判断是否含有汉字 <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>if (escape(str).indexOf("%u")!=-1) alert("含有汉字"); <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div>else alert("全是字符"); <wbr> <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>4. 邮箱格式验证 <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>//函数名:chkemail <wbr> <wbr> <wbr></div>
|
||
<div>//功能介绍:检查是否为Email Address <wbr> <wbr> <wbr></div>
|
||
<div>//参数说明:要检查的字符串 <wbr> <wbr> <wbr></div>
|
||
<div>//返回值:0:不是 1:是 <wbr> <wbr> <wbr></div>
|
||
<div>function chkemail(a) <wbr> <wbr> <wbr></div>
|
||
<div>{ var i=a.length; <wbr> <wbr> <wbr></div>
|
||
<div>var temp = a.indexOf('@'); <wbr> <wbr> <wbr></div>
|
||
<div>var tempd = a.indexOf('.'); <wbr> <wbr> <wbr></div>
|
||
<div>if (temp > 1) { <wbr> <wbr> <wbr></div>
|
||
<div>if ((i-temp) > 3){ <wbr> <wbr> <wbr></div>
|
||
<div>if ((i-tempd)>0){ <wbr> <wbr> <wbr></div>
|
||
<div>return 1; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>return 0; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>5. 数字格式验证 <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>//函数名:fucCheckNUM <wbr> <wbr> <wbr></div>
|
||
<div>//功能介绍:检查是否为数字 <wbr> <wbr> <wbr></div>
|
||
<div>//参数说明:要检查的数字 <wbr> <wbr> <wbr></div>
|
||
<div>//返回值:1为是数字,0为不是数字 <wbr> <wbr> <wbr></div>
|
||
<div>function fucCheckNUM(NUM) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>var i,j,strTemp; <wbr> <wbr> <wbr></div>
|
||
<div>strTemp="0123456789"; <wbr> <wbr> <wbr></div>
|
||
<div>if ( NUM.length== 0) <wbr> <wbr> <wbr></div>
|
||
<div>return 0 <wbr> <wbr> <wbr></div>
|
||
<div>for (i=0;i<NUM.length;i++) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>j=strTemp.indexOf(NUM.charAt(i)); <wbr> <wbr> <wbr></div>
|
||
<div>if (j==-1) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>//说明有字符不是数字 <wbr> <wbr> <wbr></div>
|
||
<div>return 0; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>//说明是数字 <wbr> <wbr> <wbr></div>
|
||
<div>return 1; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>6. 电话号码格式验证 <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>//函数名:fucCheckTEL <wbr> <wbr> <wbr></div>
|
||
<div>//功能介绍:检查是否为电话号码 <wbr> <wbr> <wbr></div>
|
||
<div>//参数说明:要检查的字符串 <wbr> <wbr> <wbr></div>
|
||
<div>//返回值:1为是合法,0为不合法 <wbr> <wbr> <wbr></div>
|
||
<div>function fucCheckTEL(TEL) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>var i,j,strTemp; <wbr> <wbr> <wbr></div>
|
||
<div>strTemp="0123456789-()# "; <wbr> <wbr> <wbr></div>
|
||
<div>for (i=0;i<TEL.length;i++) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>j=strTemp.indexOf(TEL.charAt(i)); <wbr> <wbr> <wbr></div>
|
||
<div>if (j==-1) <wbr> <wbr> <wbr></div>
|
||
<div>{ <wbr> <wbr> <wbr></div>
|
||
<div>//说明有字符不合法 <wbr> <wbr> <wbr></div>
|
||
<div>return 0; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr> <wbr></div>
|
||
<div>//说明合法 <wbr> <wbr> <wbr></div>
|
||
<div>return 1; <wbr> <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>7. 判断输入是否为中文的函数 <wbr> <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>function ischinese(s){ <wbr> <wbr></div>
|
||
<div>var ret=true; <wbr> <wbr></div>
|
||
<div>for(var i=0;i<s.length;i++) <wbr> <wbr></div>
|
||
<div>ret=ret &&(s.charCodeAt(i)>=10000); <wbr> <wbr></div>
|
||
<div>return ret; <wbr> <wbr></div>
|
||
<div>} <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div>8. 综合的判断用户输入的合法性的函数 <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div><script language="javascript"> <wbr></div>
|
||
<div>//限制输入字符的位数开始 <wbr></div>
|
||
<div>//m是用户输入,n是要限制的位数 <wbr></div>
|
||
<div>function issmall(m,n) <wbr></div>
|
||
<div>{ <wbr></div>
|
||
<div>if ((m<n) &&(m>0)) <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> { <wbr></div>
|
||
<div> <wbr> <wbr> <wbr>return(false); <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> } <wbr></div>
|
||
<div>else <wbr></div>
|
||
<div>{return(true);} <wbr></div>
|
||
<div>} <wbr></div>
|
||
<div> <wbr> <wbr></div>
|
||
<div>9. 判断密码是否输入一致 <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>function issame(str1,str2) <wbr></div>
|
||
<div>{ <wbr></div>
|
||
<div>if (str1==str2) <wbr></div>
|
||
<div>{return(true);} <wbr></div>
|
||
<div>else <wbr></div>
|
||
<div>{return(false);} <wbr></div>
|
||
<div>} <wbr></div>
|
||
<div> <wbr> <wbr></div>
|
||
<div>10. 判断用户名是否为数字字母下滑线 <wbr></div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>function notchinese(str){ <wbr></div>
|
||
<div>var reg=/[^A-Za-z0-9_]/g <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> if (reg.test(str)){ <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> return (false); <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> }else{ <wbr></div>
|
||
<div>return(true); <wbr> <wbr> <wbr> } <wbr></div>
|
||
<div>} <wbr></div>
|
||
<div><br>
|
||
</div>
|
||
<div>11. form文本域的通用校验函数</div>
|
||
<div>--------------------------------------- <wbr> <wbr> <wbr></div>
|
||
<div>作用:检测所有必须非空的input文本,比如姓名,账号,邮件地址等等。</div>
|
||
<div>该校验现在只针对文本域,如果要针对form里面的其他域对象,可以改变判断条件。</div>
|
||
<div><br>
|
||
</div>
|
||
<div>使用方法:在要检测的文本域中加入title文字。文字是在提示信息,你要提示给用户的该字段的中文名。比如要检测用户名</div>
|
||
<div>html如下<input name="txt_1"title="姓名">,当然,最好用可视化工具比如dreamweaver什么的来编辑域。</div>
|
||
<div>如果要检测数字类型数据的话,再把域的id统一为sz.</div>
|
||
<div>javascript判断日期类型比较麻烦,所以就没有做日期类型校验的程序了.高手可以补充。</div>
|
||
<div><br>
|
||
</div>
|
||
<div>程序比较草,只是提供一个思路。抛砖引玉! :)</div>
|
||
<div>哦,对了,函数调用方法:< form <wbr> <wbr> onsubmit="returndovalidate()"></div>
|
||
<div><br>
|
||
</div>
|
||
<div>function dovalidate()</div>
|
||
<div>{</div>
|
||
<div>fm=document.forms[0] //只检测一个form,如果是多个可以改变判断条件</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> for(i=0;i<fm.length;i++)</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> { <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> //检测判断条件,根据类型不同可以修改</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> if(fm.tagName.toUpperCase()=="INPUT"&&fm.type.toUpperCase()=="TEXT"&& (fm.title!=""))</div>
|
||
<div> <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>if(fm.value="/blog/="")//</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>{</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>str_warn1=fm.title+"不能为空!";</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>alert(str_warn1);</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>fm.focus();</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>return false; <wbr> <wbr> <wbr> <wbr> <wbr></div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>}</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>if(fm.id.toUpperCase()=="SZ")//数字校验</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>{</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>if(isNaN(fm.value))</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> { str_warn2=fm.title+"格式不对";</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> alert(str_warn2);</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> fm.focus();</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>return false;</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr>}</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> <wbr> <wbr> }</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> }</div>
|
||
<div> <wbr> <wbr> <wbr> <wbr> return true;</div>
|
||
<div>}</div>
|
||
<div><br>
|
||
</div>
|
||
</div>
|
||
|