Posted in Javascript onMarch 25, 2010
//检查是否非空 function notEmpty(obj, msg) { str = obj.value; str1 = ""; for (i = 0; i < str.length; i++) { if (str.charAt(i) != " ") { str1 = str.substr(i, str.length); break; } } if (str1 == "") { alert(msg); obj.value = ""; obj.focus(); return false; } else { return true; } } //检查是否为数字 function isNumber(obj, msg) { if(isNaN(obj.value)) { if (undefined == msg) { msg = "请输入数字!"; } alert(msg); obj.select(); return false; } else { return true; } } //检查密码是否相同 function isSamePwd(objPwd1, objPwd2, msg) { pwd1 = objPwd1.value; pwd2 = objPwd2.value; if (pwd1 != pwd2) { if (null == msg) { alert("密码不相同!"); } else { alert(msg); } objPwd2.value = ""; objPwd2.focus(); return false; } else { return true; } } //检查邮件地址 function isEmail(obj, msg) { ch = obj.value; if((ch.indexOf("@") < 1) || (ch.indexOf(".") < 1) || (ch.indexOf(".") == ch.length - 1)) { if (null == msg) { alert("Email不正确!"); } else { alert(msg); } obj.select(); return false; } else { return true; } }
<script language="javascript"> function checkspace(checkstr) { var str = ''; for(i = 0; i < checkstr.length; i++) { str = str + ' '; } return (str == checkstr); } function checkfrm() { if (checkspace(document.frm.title.value)) { alert('标题不能为空'); document.frm.title.focus(); return false; } if (checkspace(document.frm.truename.value)) { alert("姓名必须填写"); document.frm.truename.focus(); return false; } if (checkspace(document.frm.danwei.value)) { alert("单位名称没有填写"); document.frm.dianwei.focus(); return false; } if (checkspace(document.frm.dizhi.value)) { alert("地址不能为空"); document.frm.dizhi.focus(); return false; } if (checkspace(document.frm.content.value)) { alert("留言内容部能为空"); document.frm.content.focus(); return false; } if (checkspace(document.frm.email.value)) { alert("邮箱不能为空"); document.frm.email.focus(); return false; } return true; } </script>
js几个验证函数代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@