一個用戶註冊常用表單驗證...
<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="提 交">