网络编程
位置:首页>> 网络编程>> JavaScript>> javaScript通用数据类型校验函数(7)

javaScript通用数据类型校验函数(7)

 来源:asp之家 发布时间:2009-07-06 12:49:00 

标签:函数,JavaScript,验证

 判断当前对象及其父对象是否可见

function checkPrVis(obj){   
    var pr=obj.parentNode;   
    do{   
        if(pr == undefined || pr == "undefined") return true;   
        else{   
            if(!isVisible(pr)) return false;   
        }   
    }while(pr=pr.parentNode);   
    return true;   
}

   弹出警告对话框,用户点确定后将光标置于出错文本框上, 并且将原来输入内容选中。

function f_alert(obj,alertInfo)   
{   
    var caption = obj.getAttribute("eos_displayname");   
    if(caption == null)   
        caption = "";   
    alert(caption + ":" + alertInfo + "!");    
    obj.select();   
    if(isVisible(obj) && checkPrVis(obj))   
        obj.focus();   
}

   检测字符串是否为空


function isnull(str)   
{   
    var i;   
    if(str.length == 0)   
        return true;   
    for (i=0;i<str.length;i++)   
    {   
        if (str.charAt(i)!=' ')    
            return false;   
    }   
    return true;   
}   

 检测指定文本框输入是否合法。
* 如果用户输入的内容有错,则弹出提示对话框,
* 同时将焦点置于该文本框上,并且该文本框前面
* 会出现一个警告图标(输入正确后会自动去掉)。

 

function checkInput(object)   
{   
    var image;   
    var i;   
    var length;   
  
    if(object.eos_maxsize + "" != "undefined") length = object.eos_maxsize;   
    else length = 0;   
  
    if (object.eos_isnull=="true" && isnull(object.value))  return true;   
  
    /* 长度校验 */  
    if(length != 0 && strlen(object.value) > parseInt(length)) {   
            f_alert(object, "超出最大长度" + length);   
            return false;   
    }    
    /* 数据类型校验 */  
    else {   
        if (object.eos_datatype + "" != "undefined")   
        {          
  
            var dtype = object.eos_datatype;   
            var objName = object.name;   
            //如果类型名后面带有括号,则视括号前面的字符串为校验类型   
            if(dtype.indexOf("(") != -1)   
                dtype = dtype.substring(0,dtype.indexOf("("));   
            //根据页面元素的校验类型进行校验   
            try{   
                if(eval("f_check_" + dtype + "(object)") != true)   
                    return false;   
            }catch(e){return true;}   
            /*  如果form中存在name前半部分相同,并且同时存在以"min"和"max"结尾的表单域,  
                那么视为按区间查询。即"min"结尾的表单域的值要小于等于"max"结尾的表单域的值。 */  
            if(objName.substring((objName.length-3),objName.length)=="min")   
            {   
                var objMaxName = objName.substring(0, (objName.length-3)) + "max";   
                if(document.getElementById(objMaxName) != undefined && document.getElementById(objMaxName) != "undefined" )   
                {   
              &n, bsp;     if(checkIntervalObjs(object, document.getElementById(objMaxName)) != true)   
                        return false;                      
                }   
            }              
        }   
    }   
    return true;   

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com