一个用户注册常用表单验证...
<script Language="JavaScript" Type="text/javascript">
<!--
function Validator(theForm)
{
if (theForm.Username.value == "")
{
alert("请输入用户名!");
theForm.Username.focus();
return (false);
}
if (theForm.photofold.value =="")
{
alert("请输入相册名!");
theForm.photofold.focus();
return (false);
}
if (theForm.pass.value == "")
{
alert("请输入密码!");
theForm.pass.focus();
return (false);
}
if (theForm.pass.value.length < 6)
{
alert("密码请至少输入 6 个字符。");
theForm.pass.focus();
return (false);
}
if (theForm.pass.value !== theForm.repass.value)
{
alert("两次输入的密码不一致!");
theForm.pass.focus();
return (false);
}
if (theForm.email.value == "")
{
alert("请输入您的邮箱地址!");
theForm.pass.focus();
return (false);
}
else
{
if (theForm.email.value.charAt(0)=="." ||
theForm.email.value.charAt(0)=="@"||
theForm.email.value.indexOf('@', 0) == -1 ||
theForm.email.value.indexOf('.', 0) == -1 ||
theForm.email.value.lastIndexOf("@")==theForm.email.value.length-1 ||
theForm.email.value.lastIndexOf(".")==theForm.email.value.length-1)
{
alert("Email地址格式不正确!");
theForm.email.focus();
return false;
}
}
return (true);
}
//--></script>
<form action="adm_login.asp" method="POST" name="FormReg" id="FormReg" οnsubmit="return Validator(this)" language="JavaScript">
提交按钮:
<input name="FormReg" type="submit" value="提 交">