专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Asp教程 » js表单验证:一段表单JS验证代码 »正文

js表单验证:一段表单JS验证代码

来源: 发布时间:星期四, 2008年9月25日 浏览:515次 评论:0

<script Language=\"JavaScript\">
function FormCheck(theform)
{
if (theform.hybz.value ==\"\")
{
alert(\"请选择注册类别!\");
theform.hybz.focus();
return (false);
}
if (theform.user.value ==\"\")
{
alert(\"请填写您的用户名!\");
theform.user.focus();
return false;
}
var filter=/^\\s*[.A-Za-z0-9_-]{5,15}\\s*$/;
if (!filter.test(theform.user.value)) {
alert(\"用户名填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 _ - .)长度不小于5个字符,不超过15个字符,注意不要使用空格。\");
theform.user.focus();
theform.user.select();
return false;
}
if (theform.pass.value ==\"\")
{
alert(\"请填写您的密码!\");
theform.pass.focus();
return false;
}
if(theform.confirmPassword.value==\"\"){
alert(\"请输入您的确认密码!\");
theform.confirmPassword.focus();
return false;
}
var filter=/^\\s*[.A-Za-z0-9_-]{5,15}\\s*$/;
if (!filter.test(theform.pass.value)) {
alert(\"密码填写不正确,请重新填写!可使用的字符为(A-Z a-z 0-9 _ - .)长度不小于5个字符,不超过15个字符,注意不要使用空格。\");
theform.pass.focus();
theform.pass.select();
return false;
}
if (theform.pass.value!=theform.confirmPassword.value ){
alert(\"两次填写的密码不一致,请重新填写!\");
theform.pass.focus();
theform.pass.select();
return false;
}
if (theform.question.value ==\"\")
{
alert(\"请输入密码提示问题!\");
theform.question.focus();
return (false);
}
if (theform.answer.value ==\"\")
{
alert(\"请输入密码提示答案!\");
theform.answer.focus();
return (false);
}
if (theform.name.value ==\"\")
{
alert(\"请输入您的姓名!\");
theform.name.focus();
return (false);
}
if (theform.sf.value ==\"\")
{
alert(\"请选择区域!\");
theform.sf.focus();
return (false);
}
if (theform.city.value ==\"\")
{
alert(\"请选择城镇名!\");
theform.city.focus();
return (false);
}
if (theform.qymc.value ==\"\")
{
alert(\"请输入您的公司名称!\");
theform.qymc.focus();
return (false);
}
if (theform.qylb.value ==\"0\")
{
alert(\"请选择您的单位性质!\");
theform.qylb.focus();
return (false);
}
if (theform.address.value ==\"\")
{
alert(\"请输入您的联系地址!\");
theform.address.focus();
return (false);
}
if (theform.post.value ==\"\")
{
alert(\"请输入邮政编码!\");
theform.post.focus();
return (false);
}
if (theform.phone.value ==\"\")
{
alert(\"请输入您的联系电话!\");
theform.phone.focus();
return (false);
}
if (theform.email.value ==\"\")
{
alert(\"请输入您的电子邮件地址!\");
theform.email.focus();
theform.email.select();
return false;
}
var filter=/@/;
if (!filter.test(theform.email.value)) {
alert(\"邮件地址不正确,请重新填写!\");
theform.email.focus();
theform.email.select();
return false;
}
<!-- theform.submit() -->
}
</script>

调用代码:
表单提交时用下列代码调用

参考:[http://www.CrazyCoder.cn/]
onSubmit=\"return FormCheck(this);\"

相关文章

读者评论

  • 共0条 分0页

发表评论

  • 昵称:
  • 内容: