常用的一些正则验证

//input点击控制
function hiddenPrompt(text, id) {
    if ($("#" + id).val() == text) {
        $("#" + id).val("");
    }
}
// input焦点离开控制
function showPrompt(text, id) {
    if ($("#" + id).val() == "") {
        $("#" + id).val(text);
    }
}
/*手机号为11位*/
function checkCardId(strReserveMobile){
    var strReserveMobileReg= /^\d{11}$/;
    if(!strReserveMobileReg.test(strReserveMobile)){
        info("请输入正确的手机号");
        return false;
    }
}
/*银行卡必须是16位到19位数字*/
function checkBankcard(strBankcardNo){
    var strBankcardNoReg= /^(\d{16}|\d{19})$/;
    if(!strBankcardNoReg.test(strBankcardNo)){
        info("请输入正确的银行卡号");
        return false;
    }
}
/*身份证件号必须是18位;如果为18位,前17位必须是数字,后1位为数字或者x*/
function checkIdentity(strIdentity){
    var strIdentityReg=/^\d{18}$|^\d{17}(\d|X|x)$/;
        if(strIdentityReg.test(strIdentity)){
           var strIdentityEnd=strIdentity.substring(17,18);
           if(strIdentityEnd=="x"){
                strIdentity=strIdentity.replace('x','X');
           }
        }else{
            info("请输入正确的身份证件号");
            return false;
        }
}
/*去除空格*/
function Trim(str){ 
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

 

posted @ 2016-03-17 15:06  归尘2016  阅读(215)  评论(0编辑  收藏  举报