jquery较验组织机构编码

来源:互联网 发布:成都泰迪熊博物馆淘宝 编辑:程序博客网 时间:2024/05/24 15:39

//*************************组织机构码较验*************************

          function checkOrganizationCode()

              {

                 var weight = [3, 7, 9, 10, 5, 8, 4, 2];

                 var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

                 var reg = /^([0-9A-Z]){8}-[0-9|X]{1}$/;

                 var organizationcode = $("#organizationcode").val().trim();

                 if(organizationcode=="" || organizationcode == null)

                    { 

                        $("#checkorganizationcode").html("<font color='red'>组织机构编码不可以为空</font>");

                        return false;

                    }

                 else if(!reg.test(organizationcode))

                    { 

                        $("#checkorganizationcode").html("<font color='red'>请按格式正确填写组织机构编码,例如:05862390-X</font>");

                        return false;

                    }

                 else 

                    {

                        var sum = 0;

                        for (var i = 0; i < 8; i++) 

                           {

                              sum += str.indexOf(organizationcode.charAt(i)) * weight[i];

                           }

                        var code9 = getCheckCode(sum);

                        if(code9 == organizationcode.charAt(9))

                           {

                              $("#checkorganizationcode").html("");

                              return true;

                           }

                        else

                              $("#checkorganizationcode").html("<font color='red'>您输入的组织结构编码不正确,请仔细检查后输入</font>");

                              return false;     

                    }

              }   

              function getCheckCode(number)

                  {

                      var Remainder = 11 - (number % 11);

                      if( Remainder<10 )

                          {

                             return Remainder

                          }

                      else if(Remainder == 10)

                          {

                             return X;

                          }   

                      else 

                          return 0;

                  }

0 0