• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

表单验证

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网 <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>
。

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网