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>

posted on 2012-04-24 16:20  王培  阅读(241)  评论(0编辑  收藏  举报

导航