以下是要用到的js代码,一般单独放一个js文件,本例放置到myjs.js文件当中,以下是引用该文件的代码;   
代码如下:
 
       
var icon = '"p_w_picpath/warning.gif" width= "14" height= "14" border= "0" align= "top">';
         var ns = [ "Loginname", "Password", "Passw", "Mail", "Companyname", "Tel", "Fax", "Dizhi", "Zip", "Linkname", "Shouji", "Url", "Jieshao", "Yanzheng"];
        
         // 换一张图片
         function SetImage(){
           //  
           var rod =  Math.round(Math.random() * 100);
          $('ImaYanZhen').src = "p_w_picpath/loading.gif"; //  
          $('ImaYanZhen').src = "ValidateCode.aspx?id=" + rod;
        }
        
         function checkUsr(s){  
             var ma = [ "用户名(4-16位)!", "用户名由数字、英文、下划线、中杠线组成!"];
             if(!limitLen(s,4,16)){
             showInfo( "Loginname",ma[0]);
             return false;
            }
             if(!hasAccountChar(s)){
             showInfo( "Loginname",ma[1]);
             return false;
            }
            showInfo( "Loginname");
             return true;
        }
        
         function isLoginname(s)
        {
             var ma = [ "用户名(4-16位)!", "用户名由数字、英文、下划线、中杠线组成!", "此用户名已被注册,请另换一个。", "请等待,数据加载中..."];
             var icons = '"p_w_picpath/loading.gif" width= "14" height= "14" border= "0" align= "top">';
            
             if(!limitLen(s,4,16)){
             showInfo( "Loginname",ma[0]);
             return false;
            }
             if(!hasAccountChar(s)){
             showInfo( "Loginname",ma[1]);
             return false;
            }
            
            $( "TisiLoginname").className = "focus";
            $( "LoginnameInfo").innerHTML = icons + ma[3];
              
           var bRet = join.GetReturnCode(s).value;
           if(bRet == "1"){
                $( "TisiLoginname").className = "error";
                $( "LoginnameInfo").innerHTML = icon + ma[2];
           }
           else
           {
                showInfo( "Loginname");
           }
        }
        
       function checkPwd(s){
   var ma = [ "密码(6-20位)!", "密码不能包含中文或全角符号!", "两次输入的密码不一致!"];
   if(!limitLen(s,6,16)){
   showInfo( "Password",ma[0]);
   return false;
  }
   if(hasChineseChar(s)){
   showInfo( "Password",ma[1]);
   return false;
  }
  showInfo( "Password");
   return true;
}
  
function checkPwd2(s){
     var ma = [ "密码(6-20位)!", "密码不能包含中文或全角符号!", "两次输入的密码不一致!"];
     if(!limitLen(s,6,16)){
   showInfo( "Passw",ma[0]);
   return false;
  }
   if(hasChineseChar(s)){
   showInfo( "Passw",ma[1]);
   return false;
  }
        
         if( s==trim($( "TexPassword").value))
        {
            showInfo( "Passw");
             return true;
        }
     else{
         showInfo( "Passw",ma[2]);
       return false;
     }
}
  
function checkEml(s){
   var ma = [ "请输入常用邮件!", "邮件格式不正确!"];
   if(s.length < 5){
   showInfo( "Mail",ma[0]);
   return false;
  }
   if(!isEmail(s)){
   showInfo( "Mail",ma[1]);
   return false;
  }
  showInfo( "Mail");
   return true;
}
  
   function checkCompany(s){  
   var ma = [ "企业名称不能为空!"];
   if(!limitLen(s,1,100)){
   showInfo( "Companyname",ma[0]);
   return false;
  }
  showInfo( "Companyname");
   return true;
}  
  
   function checkPhone(){  
       var ma = [ "电话国家代码不能为空!", "电话区号不能为空!", "电话号码不正确!"];
       var gj = $( "TexTelGJ").value;
       var qh = $( "TexTelQH").value;
       var s = $( "TexTel").value;
       if(gj.length == 0){
       showInfo( "Tel",ma[0]);
       return false;
      }
       if(qh.length == 0){
       showInfo( "Tel",ma[1]);
       return false;
      }  
       if(!isPhone(gj + "-" + qh+ "-" + s)){
       showInfo( "Tel",ma[2]);
       return false;
      }  
      showInfo( "Tel");
       return true;
     }  
        
         function checkFax(){
             var ma = [ "传真国家代码不能为空!", "传真区号不能为空!", "传真号码不正确!"];
       var gj = $( "TexFaxGJ").value;
       var qh = $( "TexFaxQH").value;
       var s = $( "TexFax").value;
        
       if(gj.length == 0 && qh.length == 0 && s.length == 0)
      {
          $( "TisiFax").className = "lond";
          $( "FaxInfo").innerHTML = "";
           return true;
      }
       if(gj.length == 0){
       showInfo( "Fax",ma[0]);
       return false;
      }
       if(qh.length == 0){
       showInfo( "Fax",ma[1]);
       return false;
      }  
       if(!isPhone(gj + "-" + qh + "-" + s)){
       showInfo( "Fax",ma[2]);
       return false;
      }  
      showInfo( "Fax");
       return true;
        }
        
        
         function checkDizi(s){  
             var ma = [ "企业地址不能为空!"];
             if(!limitLen(s,1,100)){
             showInfo( "Dizhi",ma[0]);
             return false;
            }
            showInfo( "Dizhi");
             return true;
        }
        
     function checkZip(s){
             var ma = [ "邮政编码格式不正确!"];
             if(s.length == 0){
                $( "TisiZip").className = "lond";
          $( "ZipInfo").innerHTML = "中国地区用户请填写规范的6位邮政编码。";
           return true;
            }
             if(!isZip(s)){
             showInfo( "Zip",ma[0]);
             return false;
            }
            showInfo( "Zip");
             return true;
     }
      
     function checkShengfen(){
             var ma = [ "请选择公司所在省份!", "请选择公司所在市区!"];
             var sh,qu;
            sh = $( "DropShengfen").selectedIndex;
            qu = $( "DropDiqu").selectedValue;
             if(sh == 0){
                showInfo( "Shengfen",ma[0]);
                 return false;
            }
             if(qu == ""){
                showInfo( "Shengfen",ma[1]);
                 return false;
            }
            showInfo( "Shengfen");
             return true;
     }
      
     function checkLinkname(s){
         var ma = [ "联系人不能为空!"];
       if(!limitLen(s,2,20)){
       showInfo( "Linkname",ma[0]);
       return false;
      }
      showInfo( "Linkname");
       return true;
    }
    
     function checkShouji(s){
         var ma = [ "手机格式不正确!"];
         if(s.length == 0){
             $( "TisiShouji").className = "lond";
          $( "ShoujiInfo").innerHTML = "建议您填写,以便潜在客户及时与您取得联系!";
           return true;
         }
         if(!isMobile(s)){
             showInfo( "Shouji",ma[0]);
             return false;
         }
      showInfo( "Shouji");
       return true;
    }
    
     function checkUrl(s){
         var ma = [ "网址格式不正确!"];
         if(s == "HTTP://" || s.length == 0){
             $("TisiUrl").className = "lond";
          $("UrlInfo").innerHTML = "请在网址前加:HTTP://。";
          return true;
         }
         if(!isURL(s)){
             showInfo("Url",ma[0]);
             return false;
         }
      showInfo("Url");
      return true;
    }
    
    function checkJieshao(s){
         var ma = ["企业介绍不能为空!"];
      if(!limitLen(s,1,2000)){
       showInfo("Jieshao",ma[0]);
       return false;
      }
      showInfo("Jieshao");
      return true;
    }
    
    
    function checkYanzheng(s){
         var ma = ["验证码不能为空!","验证码为4位字母或数字!","验证码输入错误,请重新输入!"];
         if(s.length == 0)
         {
             showInfo("Yanzheng",ma[0]);
             return false;
         }
         if(s.length < 4)
         {
             showInfo("Yanzheng",ma[1]);
             return false;
         }else{
            var ses = join.sessions().value;
            if(s.toLowerCase() != ses)
            {
                 showInfo("Yanzheng",ma[2]);
                 return false;
            }
        }
        showInfo("Yanzheng");
     return true;
    }
    
        function inputfocus(n,i)
        {
            var ma = ["4-16位;只限数字(0-9)和英文(a-z),不区分大小写;建议使用公司名称简称。",
                "6-20位,区分大小写, 不能与用户名相同;建议为英文字母(a-z)和数字(0-9)结合,便于记忆,不易被猜出。",
                "请再输入一遍上面填写的密码。",
                "请填写常用的电子邮箱,这是客户联系您的一种方式!",
                "请使用中文填写贵公司的全称。",
                "很重要!这是客户联系您的主要方式!",
                "请填写完整的公司地址。",
                "中国地区用户请填写规范的6位邮政编码。",
                "请选择公司所在省市。",
                "请填写联系人的真实姓名。",
                "建议您填写,以便潜在客户及时与您取得联系!",
                "请在网址前加:HTTP://。",
                "可以填入最多2000字的企业介绍。",
                "请输入左侧显示的验证字符串(不区分大小写)。"];
            var fdo = $("Tisi" + n);
            var ido = $(n + "Info");
            fdo.className = "focus";
            ido.innerHTML = ma[i];
        }
        
        function showInfo(n,s){
            var fdo = $("Tisi" + n);
            var ido = $(n + "Info");
            if(typeof s == 'undefined'){
                fdo.className = "ok";
                ido.innerHTML = "填写正确!";
            }else{
                fdo.className = "error";
                ido.innerHTML = icon + s;
            }
        }
        
        function submits(){
            checkUsr($("Tex" + ns[0]).value);
            checkPwd($("Tex" + ns[1]).value);
            checkPwd2($("Tex" + ns[2]).value);
            checkEml($("Tex" + ns[3]).value);
            checkCompany($("Tex" + ns[4]).value);
            checkPhone();
            checkFax();
            checkDizi($("Tex" + ns[7]).value);
            checkZip($("Tex" + ns[8]).value);
            checkShengfen();
            checkLinkname($("Tex" + ns[9]).value);
            checkShouji($("Tex" + ns[10]).value);
            checkUrl($("Tex" + ns[11]).value);
            checkJieshao($("Tex" + ns[12]).value);
            checkYanzheng($("Tex" + ns[13]).value);
            
            for(var i=0;i               if( $("Tisi" + ns[i]).className == "error"){
                    $("Tex" + ns[i]).focus();  
                   return false;
               }
               else{
                    continue;
               }
            }
           // return true;
        var  fax = "", fw = "", mes = "由于网络原因注册失败,请联系管理人员。";
        var baomi = 0;
        var tel =  $("TexTelGJ").value + "-" + $("TexTelQH").value +"-"+$("TexTel").value;
        
        if(trim($("TexFax").value) != ""){
            fax =  $("TexFaxGJ").value + "-" + $("TexFaxQH").value +"-"+$("TexFax").value;
        }
        
        for(var i =1;i<7;i++){
            if($("CheckBox" + i).Checked == "Checked"){
                fw += $("CheckBox" + i).value + ",";
                }
        }
        
        if($("RadioButtonList1_0").checked == "checked"){
            baomi = 0;
            }
            else{
            baomi = 1;
            }
            
        var a1 = $("TexLoginname").value;
        var a2 = $("TexPassword").value;
        var a3 = $("TexMail").value;
        var a4 = $("TexCompanyname").value;
        var a5 = $("TexDizhi").value;
        var a6 = $("TexZip").value;
        var a7 = $("DropShengfen").value;
        var a8 = $("DropDiqu").value;
        var a9 = $("TexLinkname").value;
        var a10 = $("TexShouji").value;
        var a11 = $("TexUrl").value;
        var a12 = $("DropDownList3").value;
        var a13 = $("TexJieshao").value;
          
        var bRet = join.AddCompanya(a1,a2,a3,a4,tel, fax,a5,a6,a7,a8,a9,a10,baomi,a11,a12, fw,a13,$('HidIP').value).value;
        
        if(bRet == "1"){
            location.href="Default.aspx";
        }
        else{
             alert(bRet);
        }
            // 调用后台的代码 写入数据库
        }
        function initPage(){
            for(var i=0;i                $("Tex" + ns[i]).value = "";
            }
        }


说明:
 
以下是代码的应用,请参考:
 
"TexPassword" runat= "server" BorderStyle= "Groove" MaxLength= "16"  onfocus= "inputfocus('Password',1)" onkeyup= "checkPwd(this.value);" onblur= "checkPwd(this.value);"
                            TextMode= "Password" Width= "150px">



"TexPassw" runat= "server" BorderStyle= "Groove" MaxLength= "16" onfocus= "inputfocus('Passw',2)" onkeyup= "checkPwd2(this.value);" onblur= "checkPwd2(this.value);" Width= "150px" TextMode= "Password">.........................................................
 
如果支持本博文,请劳烦动动鼠标,点下下面的广告 ,绿色无公害,请放心点击:):):)