熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

一段表單JS驗證代碼

2013-11-13 10:20:58  來源: .NET編程 

  <script Language=\JavaScript\>
function FormCheck(theform)
{
if (theformhybzvalue ==\\)
{
alert(\請選擇注冊類別!\);
theformhybzfocus();
return (false);
}
if (theformuservalue ==\\)
{
alert(\請填寫您的用戶名!\);
theformuserfocus();
return false;
}
var filter=/^\\s*[AZaz_]{}\\s*$/;
if (!filtertest(theformuservalue)) {
alert(\用戶名填寫不正確請重新填寫!可使用的字符為(AZ az _ )長度不小於個字符不超過個字符注意不要使用空格\);
theformuserfocus();
theformuserselect();
return false;
}
if (theformpassvalue ==\\)
{
alert(\請填寫您的密碼!\);
theformpassfocus();
return false;
}
if(nfirmPasswordvalue==\\){
alert(\請輸入您的確認密碼!\);
nfirmPasswordfocus();
return false;
}
var filter=/^\\s*[AZaz_]{}\\s*$/;
if (!filtertest(theformpassvalue)) {
alert(\密碼填寫不正確請重新填寫!可使用的字符為(AZ az _ )長度不小於個字符不超過個字符注意不要使用空格\);
theformpassfocus();
theformpassselect();
return false;
}
if (theformpassvalue!=nfirmPasswordvalue ){
alert(\兩次填寫的密碼不一致請重新填寫!\);
theformpassfocus();
theformpassselect();
return false;
}
if (theformquestionvalue ==\\)
{
alert(\請輸入密碼提示問題!\);
theformquestionfocus();
return (false);
}
if (theformanswervalue ==\\)
{
alert(\請輸入密碼提示答案!\);
theformanswerfocus();
return (false);
}
if (theformnamevalue ==\\)
{
alert(\請輸入您的姓名!\);
theformnamefocus();
return (false);
}
if (theformsfvalue ==\\)
{
alert(\請選擇區域!\);
theformsffocus();
return (false);
}
if (theformcityvalue ==\\)
{
alert(\請選擇城鎮名!\);
theformcityfocus();
return (false);
}
if (theformqymcvalue ==\\)
{
alert(\請輸入您的公司名稱!\);
theformqymcfocus();
return (false);
}
if (theformqylbvalue ==\\)
{
alert(\請選擇您的單位性質!\);
theformqylbfocus();
return (false);
}
if (theformaddressvalue ==\\)
{
alert(\請輸入您的聯系地址!\);
theformaddressfocus();
return (false);
}
if (theformpostvalue ==\\)
{
alert(\請輸入郵政編碼!\);
theformpostfocus();
return (false);
}
if (theformphonevalue ==\\)
{
alert(\請輸入您的聯系電話!\);
theformphonefocus();
return (false);
}
if (theformemailvalue ==\\)
{
alert(\請輸入您的電子郵件地址!\);
theformemailfocus();
theformemailselect();
return false;
}
var filter=/@/;
if (!filtertest(theformemailvalue)) {
alert(\郵件地址不正確請重新填寫!\);
theformemailfocus();
theformemailselect();
return false;
}
<! theformsubmit() >
}
</script>

  調用代碼
表單提交時用下列代碼調用

  onSubmit=\return FormCheck(this);\


From:http://tw.wingwit.com/Article/program/net/201311/13329.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.