一个简略的表单验证类 大神帮忙修修 拜托拜托

一个简单的表单验证类 大神帮忙修修 拜托拜托!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>表单验证</title>
</head>
<script type="text/javascript">

 var list = new Array(
 new FormField("name",/^[^\s][\S\s]{1,20}$/),
 new FormField("mima",/^[^\s][\S\s]{1,20}$/)
 );

function FormField(cheNameID,cheGeShi,cheSame)
{
  this.InputId = cheNameID;
  this.InputGeShi = cheGeShi;
  this.InputSame = cheSame;
}

function CheckForm(Thform){
  
    for(var i = 0; i<list.length;i++)
{
       var CheckValue = document.getElementById(list[i].InputId).value;
   var CheckNameID = document.getElementById(list[i].InputId);
       var CheckGeShi = eval(list[i].InputGeShi);
   var CheckSame = list[i].InputSame;   
   
           if(!CheckGeShi.test(CheckValue))
     {
       alert("表单A或B格式不正确!");
       CheckNameID.focus();
       return false;
     }
         
    }

  alert("验证通过!");
  return false;
}

</script>
<body>

   <form name="formA" onSubmit="return CheckForm(this);">
   <table width="260" border="1" cellspacing="1" cellpadding="2">
     <tr>
       <td>用户名:</td>
       <td><input name="name" id="name" size="18" maxlength="20"></td>
     </tr>
     <tr>
      <td>密码:</td>      
  <td><input name="mima" id="mima" size="18" maxlength="20" autocomplete="off"></td>
     </tr>
     <tr>
  <td colspan="2" align="center"><input type="submit" name="button" value="验证"></td>
     </tr>
   </table>
   </form>
   <br />
   <form name="formB" onSubmit="return CheckForm(this);">
   <table width="260" border="1" cellspacing="1" cellpadding="2">
     <tr>
       <td>用户名:</td>
       <td><input name="name" id="name" size="18" maxlength="20"></td>
     </tr>
     <tr>
      <td>密码:</td>      
  <td><input name="mima" id="mima" size="18" maxlength="20" autocomplete="off"></td>
     </tr>
     <tr>
  <td colspan="2" align="center"><input type="submit" name="button" value="验证"></td>
     </tr>
   </table>
   </form> 
</body>
</html>




如果一个页面只有一个form那这个验证没有问题,出现多个的话就over了

想要实现的是A是A,B是B  动态判断到底是哪个表单提交过来的

大神能帮忙修改一些更好!拜托!


------解决思路----------------------

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
</head>
<body>
<form name="formA" onSubmit="return CheckForm(this);">
    <table width="260" border="1" cellspacing="1" cellpadding="2">
        <tr>
            <td>用户名:</td>
            <td><input name="name" data-role="name" size="18" maxlength="20"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input name="mima" data-role="mima" size="18" maxlength="20" autocomplete="off"></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" name="button" value="验证"></td>
        </tr>
    </table>
</form>
<br />
<form name="formB" onSubmit="return CheckForm(this);">
    <table width="260" border="1" cellspacing="1" cellpadding="2">
        <tr>
            <td>用户名:</td>
            <td><input name="name" data-role="name" size="18" maxlength="20"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input name="mima" data-role="mima" size="18" maxlength="20" autocomplete="off"></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="submit" name="button" value="验证"></td>
        </tr>
    </table>
</form>
<script type="text/javascript">

        var list = [
                new FormField("name",/^[^\s][\S\s]{1,20}$/),
                new FormField("mima",/^[^\s][\S\s]{1,20}$/)
            ]
        function  getElementByCustomSign(dom,sign,value){
            var eles=dom.getElementsByTagName("*"),
                arr=[];
            for(var i= 0,len=eles.length;i<len;i++){
                if(eles[i].getAttribute(sign)==value){
                    arr.push(eles[i]);
                }
            }
            return arr;
        }
        function FormField(cheNameID,cheGeShi,cheSame){
            this.InputId = cheNameID;
            this.InputGeShi = cheGeShi;
            this.InputSame = cheSame;
        }
        function CheckForm(Thform){
            for(var i = 0; i<list.length;i++){
                var CheckValue = getElementByCustomSign(Thform,'data-role',list[i].InputId)[0].value;
                var CheckNameID = getElementByCustomSign(Thform,'data-role',list[i].InputId)[0];
                var CheckGeShi = list[i].InputGeShi;
                var CheckSame = list[i].InputSame;
                if(!CheckGeShi.test(CheckValue)){
                    alert(Thform.getAttribute('name')+"格式不正确!");
                    CheckNameID.focus();
                    return false;
                }
            }
            alert("验证通过!");
            return false;
        }
    </script>
</body>
</html>

一个页面不要有相同的id