您的位置:首页 > 其它

常用的一些正则验证

2016-03-17 15:06 155 查看
//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, "");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: