JS验证控件合法性方法代码

<script type="text/javascript">
//  验证合法性
function validate(name,zname,length)
{
     var str=eval("document.all['" + name + "'].value;");
     var strlength = parseInt(length);
     if(str == "")
    {
         Alert("输入的"+zname+"信息内容不能为空!",'','','提示', function gotomethod()
                                                          {
                                                            eval("document.all['"+name+"'].focus();")
                                                          },''); 
         return  false;
    }
     if(str.length>strlength)
    {
         Alert("输入的"+zname+"信息长度不能大于"+strlength+"!",'','','提示', function gotomethod()
                                                                  {
                                                                    eval("document.all['"+name+"'].focus();")
                                                                  },''); 
         return  false;
    }
     return  true;
}
</script>

你可能感兴趣的:(js)