YangPengFe1/yunydemo

这里是一些难找的正则

YangPengFe1 opened this issue · 0 comments

jck.isCardNo = function (s) {
    //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
    var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

//获得字符串实际长度,中文2,英文1
//<param name="s">要获得长度的字符串</param>
jck.getLength = function (s) {
    var l = 0, len = s.length, charCode = -1;
    for (var i = 0; i < len; i++) {
        charCode = s.charCodeAt(i);
        if (charCode >= 0 && charCode <= 128) l += 1;
        else l += 2;
    }
    return l;
};


jck.IsURL = function (str_url) {
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
  + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@  
        + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184  
        + "|" // 允许IP和DOMAIN(域名) 
        + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.  
        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名  
        + "[a-z]{2,6})" // first level domain- .com or .museum  
        + "(:[0-9]{1,4})?" // 端口- :80  
        + "((/?)|" // a slash isn't required if there is no file name  
        + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
    var re = new RegExp(strRegex);
    //re.test() 
    if (re.test(str_url)) {
        return (true);
    } else {
        return (false);
    }
}

//限制字符只能是中文、字母、数字、_、$、.、@、-、(、)、顿号、*、空格、·、#、全角字符
//<param name="s">要判断的字符串</param>
jck.isLimitString = function (s) {
    var reg = /^[\u4e00-\u9fa5\w_\$\.\@\-\(\)\【\】\ \*\、\#\·\uFF00-\uFFFF]*$/g;
    //var reg = /^[^'\\]+$/
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

//限制字符只能是中文、英文、数字、_、$、.、-、(、)、【、】、顿号、*
//用户帐号限制
jck.isLimitAccount = function (s) {
    var reg = /^[\u4e00-\u9fa5\w_\$\.\-\(\)\【\】\*\、\uFF00-\uFFFF]*$/g;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

//限制字符只能是英文、数字、下划线、减号、“@”、“.”、"【"、"】"、“$”
//用户帐号限制
jck.isLimitPinYin = function (s) {
    var reg = /^[a-zA-Z0-9\w_\@\$\.\-\(\)\【\】\*\、\uFF00-\uFFFF]*$/g;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

//验证电子邮箱
jck.checkEmail = function (s) {
    var reg = /^([a-zA-Z0-9\_\-\.])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,10}){1,9})$/;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

//获取URL传入参数值
jck.QueryString = function (Name, LocationSearch) {
    var sValue = null;
    if (LocationSearch == null)
        sValue = location.search.match(new RegExp("[\?\&]" + Name + "=([^\&]*)(\&?)", "i"));
    else
        sValue = LocationSearch.match(new RegExp("[\?\&]" + Name + "=([^\&]*)(\&?)", "i"));
    return sValue ? sValue[1] : sValue;
};

//电话号码验证
jck.checkPhoneNumber = function (s) {
    //var reg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    var reg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)){1,12})+$/;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};


jck.checkIsNumber = function (s) {
    //var reg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    var reg = /^\d+$/;
    if (reg.test(s) === false) {
        return false;
    }
    return true;
};

jck.checkIP = function (str) { //IP正则表达式
    IP = '(25[0-5]|2[0-4]\\d|1\\d\\d|\\d\\d|\\d)';
    IPdot = IP + '\\.';
    isIPaddress = new RegExp('^' + IPdot + IPdot + IPdot + IP + '$');
    //验证IP,返回结果
    return (isIPaddress.test(str));
}

//截取字符串
jck.subString = function (str, length, left) {
    var len = this.getLength(str);
    if (len <= length) return str;
    var t1 = str.replace(/([\u0391-\uffe5])/ig, '$1a');
    var idx = (left === false) ? (len - length) : 0;
    var idxEnd = (left === false) ? len : length;
    var t2 = t1.substring(idx, idxEnd);
    return t3 = t2.replace(/([\u0391-\uffe5])a/ig, '$1');
};

///举例:alert(compareDate('2004-12-01','2004-05-02'));目前支持年-月-日这样的格式
///比较日期大小
///哪果第一个日期参数大于第二个日期参数返回值为true,返之返回false
jck.compareDate = function (DateOne, DateTwo) {

    var OneMonth = DateOne.substring(5, DateOne.lastIndexOf("-"));
    var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf("-") + 1);
    var OneYear = DateOne.substring(0, DateOne.indexOf("-"));

    var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf("-"));
    var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf("-") + 1);
    var TwoYear = DateTwo.substring(0, DateTwo.indexOf("-"));

    if (Date.parse(OneMonth + "/" + OneDay + "/" + OneYear) > Date.parse(TwoMonth + "/" + TwoDay + "/" + TwoYear)) {
        return true;
    }
    else {
        return false;
    }

}

///全角空格为12288,半角空格为32 
///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248 
//半角转换为全角函数
jck.toDBC = function (txtstring) {
    var tmp = "";
    for (var i = 0; i < txtstring.length; i++) {
        var charC = txtstring.charCodeAt(i);
        if (charC == 32) {//空格
            tmp += String.fromCharCode(12288);
        }
        else if (charC < 127) {
            tmp += String.fromCharCode(charC + 65248);
        }
        else tmp += String.fromCharCode(charC);
    }
    return tmp;
}
jck.specialCharToDBC = function (txtstring) {
    var tmp = "";
    for (var i = 0; i < txtstring.length; i++) {
        var charC = txtstring.charCodeAt(i);
        if (charC == 32) {
            tmp += String.fromCharCode(12288);
        }
        else if (charC < 48 || charC > 57 && charC < 65 || charC > 90 && charC < 97 || charC > 122 && charC < 127) {
            tmp += String.fromCharCode(charC + 65248);
        }
        else tmp += String.fromCharCode(charC);
    }
    return tmp;
}
jck.limtCharToDBC = function (txtstring) {
    var tmp = "";
    for (var i = 0; i < txtstring.length; i++) {
        var charC = txtstring.charCodeAt(i);
        //        if (charC == 32) {//空格
        //            tmp += String.fromCharCode(12288);
        //        }
        //        else 
        if (charC == 39) {//“'”号
            tmp += String.fromCharCode(charC + 65248);
        }
        else tmp += String.fromCharCode(charC);
    }
    return tmp;
}

//全角转换为半角函数 
jck.toCDB = function (str) {
    var tmp = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) > 65248 && str.charCodeAt(i) < 65375) {
            tmp += String.fromCharCode(str.charCodeAt(i) - 65248);
        }
        else {
            tmp += String.fromCharCode(str.charCodeAt(i));
        }
    }
    return tmp
}