·您的位置: 首页 » 资源教程 » 编程开发 » JavaScript » 表单验证

表单验证

类别: JavaScript教程  评论数:0 总得分:0
<script language="javascript">
<!--

function bbs(theForm)
{
if (theForm.user.value == "")
{
alert("请输入用户名!");
theForm.user.focus();
return (false);
}
if (checktext(theForm.user.value))
{
alert("请您输入有效用户名!");
theForm.user.select();
theForm.user.focus();
return (false);
}


if (theForm.passwd.value == "")
{
alert("请输入密码!");
theForm.passwd.focus();
return (false);
}
if (checktext(theForm.passwd.value))
{
alert("请您输入有效密码!");
theForm.passwd.select();
theForm.passwd.focus();
return (false);
}




var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var checkStr = theForm.user.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}


if (!allValid)
{
alert("您输入的用户名不能含有字符 < / > \' ! =等!");
theForm.user.focus();
return (false);
}
if (checktext(theForm.user.value))
{
alert("您输入的用户名不能含有字符 < / > \' ! =等!");
theForm.user.select();
theForm.user.focus();
return (false);
}


var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var checkStr = theForm.passwd.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}


if (!allValid)
{
alert("您输入的密码不能含有字符 < / > \' ! =等!");
theForm.passwd.focus();
return (false);
}
if (checktext(theForm.passwd.value))
{
alert("您输入的密码不能含有字符 < / > \' ! =等!");
theForm.passwd.select();
theForm.passwd.focus();
return (false);
}

}

function bbs1(theForm)
{if (theForm.keyword.value == "")
{
alert("请输入关键字!");
theForm.keyword.focus();
return (false);
}
if (checktext(theForm.keyword.value))
{
alert("请输入关键字!");
theForm.keyword.select();
theForm.keyword.focus();
return (false);
}
}

function bbs3(theForm)
{

if (theForm.passwd.value == "" || theForm.passwd1.value == "")
{
alert("请输入密码!");
theForm.passwd.focus();
return (false);
}

if (theForm.passwd.value.length <4 || theForm.passwd.value.length>7)
{
alert("请输入密码必须在4-6位!");
theForm.passwd.focus();
return (false);
}
if(theForm.passwd.value != theForm.passwd1.value)
{
alert("两次密码输入不一致")
theForm.passwd.select();
theForm.passwd.focus();
return (false);
}
if(theForm.psda.value == "")
{alert("输入密码提示问题!")
theForm.psda.select();
theForm.psda.focus();
return (false);
}

if(theForm.psdq.value == "")
{alert("输入密码提示答案!")
theForm.psdq.select();
theForm.psdq.focus();
return (false);
}
if (theForm.email.value == "")
{
alert("请您输入您的"E-Mail"联系方式!");
theForm.email.focus();
return (false);
}

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
var checkStr = theForm.email.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}

if (theForm.email.value.length < 6)
{
allValid = false;
}

if (!allValid)
{
alert("您输入的 "电子邮件地址" 无效!");
theForm.email.focus();
return (false);
}

address=theForm.email.value;
if(address.length>0)
{
i=address.indexOf("@");
if(i==-1)
{
window.alert("对不起!您输入的电子邮件地址是错误的!")
theForm.email.focus();
return false
}
ii=address.indexOf(".")
if(ii==-1)
{
window.alert("对不起!您输入的电子邮件地址是错误的!")
theForm.email.focus();
return false
}

}
if (checktext(theForm.email.value))
{
alert("请您输入有效的"E-Mail"!");
theForm.email.select();
theForm.email.focus();
return (false);
}

}

function bbs4(theForm)
{
if (theForm.name.value == "")
{
alert("请输入用户名!");
theForm.name.focus();
theForm.name.select();
return (false);
}

if (theForm.name.value.length >10)
{
alert("输入的用户名必须是10个英文字符或5个汉字!");
theForm.name.focus();
theForm.name.select();
return (false);
}
if (checktext(theForm.name.value))
{
alert("请您输入有效用户名!");
theForm.name.select();
theForm.name.focus();
return (false);
}
}
function XPGuestBook(theForm)
{
if (theForm.name.value == "")
{
alert("请告诉我您的名字!");
theForm.name.focus();
return (false);
}
if (checktext(theForm.name.value))
{
alert("请您输入有效姓名!");
theForm.name.select();
theForm.name.focus();
return (false);
}


if (theForm.email.value == "")
{
alert("请您输入您的"E-Mail"联系方式!");
theForm.email.focus();
return (false);
}

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
var checkStr = theForm.email.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}

if (theForm.email.value.length < 6)
{
allValid = false;
}

if (!allValid)
{
alert("您输入的 "电子邮件地址" 无效!");
theForm.email.focus();
return (false);
}

address=theForm.email.value;
if(address.length>0)
{
i=address.indexOf("@");
if(i==-1)
{
window.alert("对不起!您输入的电子邮件地址是错误的!")
theForm.email.focus();
return false
}
ii=address.indexOf(".")
if(ii==-1)
{
window.alert("对不起!您输入的电子邮件地址是错误的!")
theForm.email.focus();
return false
}

}
if (checktext(theForm.email.value))
{
alert("请您输入有效的"E-Mail"!");
theForm.email.select();
theForm.email.focus();
return (false);
}

if (theForm.subject.value == "")
{
alert("请注明本次留言的主题!");
theForm.subject.focus();
return (false);
}



}

function checktext(text)
{
allValid = true;

for (i = 0; i < text.length; i++)
{
if (text.charAt(i) != " ")
{
allValid = false;
break;
}
}

return allValid;
}
//-->
</script>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1