当前位置: 代码迷 >> JavaScript >> verify.js资料二
  详细解决方案

verify.js资料二

热度:291   发布时间:2012-10-31 14:37:31.0
verify.js文件二
function chkLen(field_name, allow_len, label_name,defaultEmpty) {
        var s =trim(field_name.value);
        if (typeof(defaultEmpty) == "undefined") defaultEmpty = true;
        if(isEmpty(s)) {
if (!defaultEmpty) {
               field_name.focus();
               field_name.style.background=fieldbg;
               alert ("Please input " + label_name);
               return false;
        } else return true;
}
if (getTextLen(s) > allow_len) {
field_name.focus();
field_name.style.background=fieldbg;
alert(label_name + " length not more than " + allow_len + " bytes,Please reInput!");
return false;
}
return true;
}

function chkEmail(field_name,label_name,defaultEmpty) {
        var s = field_name.value;
var str = /^[_\-\.0-9a-zA-Z-]+@([0-9a-zA-Z-]+\.)+[a-zA-Z]{2,3}$/;
if (typeof(defaultEmpty) == "undefined") defaultEmpty = true;
if(isEmpty(s)) {
if (!defaultEmpty) {
               field_name.focus();
               field_name.style.background=fieldbg;
               alert ("Please input " + label_name);
               return false;
        } else return true;
}
if (!str.test(s))  {
            field_name.focus();
        field_name.style.background=fieldbg;
        alert(label_name+" input invalid,Please input right Email.");
        return false;
        }
return true;
}

function chkMoreEmail(field_name,label_name,defaultEmpty,seperator) {
var s = field_name.value;
var str = /^[_\-\.0-9a-zA-Z-]+@([0-9a-zA-Z-]+\.)+[a-zA-Z]{2,3}$/;
var ss=s.split(seperator);
var mail;
if (typeof(defaultEmpty) == "undefined") defaultEmpty = true;
if(isEmpty(s)) {
if (!defaultEmpty) {
               field_name.focus();
               field_name.style.background=fieldbg;
               alert ("Please input " + label_name);
               return false;
        } else return true;
}
for( var i=0;i<ss.length;i++){
mail=ss[i];
if (!str.test(mail))  {
            field_name.focus();
        field_name.style.background=fieldbg;
        alert(label_name+" input invalid,Please input right Email.");
        return false;
        }
}
return true;
}

function chkNum(field_name,label_name,defaultEmpty) {
if (typeof(defaultEmpty) == "undefined") defaultEmpty = true;
        var s = field_name.value;
        if(isEmpty(s)) {
if (!defaultEmpty) {
               field_name.focus();
               field_name.style.background=fieldbg;
               alert ("Please input " + label_name);
               return false;
        } else return true;
         }
         if (!isNum(s)) {
         field_name.focus();
        field_name.style.background=fieldbg;
        alert(label_name+" not valid,Please input Number!");
        return false;
         }
         return true;
}

function chkCharNum(field_name,label_name,defaultEmpty) {
    if (typeof(defaultEmpty) == "undefined") defaultEmpty = true;
    var s = field_name.value;
    if(isEmpty(s)) {
if (!defaultEmpty) {
               field_name.focus();
               field_name.style.background=fieldbg;
               alert ("Please input " + label_name);
               return false;
        } else return true;
    }
    if (!isCharNum(s)) {
    field_name.focus();
    field_name.style.background=fieldbg;
    alert(label_name+" input invalid,Please input number or letter!");
    return false;
    }
    return true;
}
  相关解决方案