检查字符串的长度
function fucchecklength(strTemp)
{
var i,sum;
sum=0;
for(i=0;i<strTemp.length;i++)
{
if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
sum=sum+1;
else
sum=sum+2;
}
return sum;
}//清除全部空格
function trimAll(strValue)
{
var objRegExp = /^(\s*)$/;
if(objRegExp.test(strValue))
{
strValue = strValue.replace(objRegExp, '');
if(strValue.length == 0) return strValue;
} objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
if(objRegExp.test(strValue))
{
strValue = strValue.replace(objRegExp, '$2');
}
return strValue;
}
if (trimAll(theform.textname.value)=='')//是否为空
if (fucchecklength(theform.textname.value)>20)//检查长度,对中文也有效

解决方案 »

  1.   

    对不起,我没有把重点说清楚,我是不知道如何循环处理jsp中动态生成的那一组input,
    还请再次解答,谢谢!!
      

  2.   

    eval("document.aaaa"+i).value!='' && eval("document.aaaa"+i).value.length!=10var elem;
    for (var i=0; i< xx; i++){
      elem = eval("document.formName.aaaa"+i);
      check(elem);
    }
      

  3.   

    <form.........
    <input ..........
    </form>明白?
      

  4.   

    function check(form)
    { if((form.name.value==null)&&(form.name.value==""))
        { alert("请输入姓名"); return false; }
      else((form.password.value==null)&&(form.password.value=="")
         { alert(请输入口令);  return false; }
      else {  return true;    }
    }<body>
    <form name=form onclick="return check(this)" action="../../*.jsp">
    <input type="text" name="name" value="20">
    <input type="password" name="password" value="20">
    <input type="submit" value="登录">
    </form>
    </body>里面的东西你可以根据自己的需要判断,我的思路比较笨,楼上的都写的较好