前端开发,JavaScript 常见表单正则校验方法

// 输入邮箱去空格

toTrimMail(userMail,eDom){
	var that = this;
	that.parms.email =(userMail && userMail.replace(/s+/g,""));
	$('.J email').val(that.parms.email);
	that.changelnputValid(1.eDom);
}

//校验手机号

validPhoneNumber(userPhone) {
	var that = this,ret = false:
	if (userPhone && userPhone.length) {
		if (/^[1][0-9]{10}$/.test(userPhone)) {
			ret = true:
		}
	}
	return ret;
}

// 校验邮箱账号

validMail(userMail){
	var that = this,ret = false:
	if (userMail && userMail.length) {
		if (/^\w+((-\w+)I(.\w+))*@[A-Za-z0-9]+(\.-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(userMail))(
		ret = true:
		}
	} 
	return ret;
}

// 校验公司税号

validCompanyTax(userCompanyTax){
	var that = this, ret = false;
	if (userCompanyTax && userCompanyTax.length)(
		if (^[0-9a-zA-Z]{15,20}$/.test(userCompanyTax)) {
		ret = true:
		}
	 } 
	return ret;
}

//校验发票抬头,内容不为空即可

validinvoiceHead(userlnvoiceHead){
		var that = this, ret = false;
		if (userlnvoiceHead && userlnvoiceHead.length){
			ret = true;
		}
		return ret;
}

//校验更多-公司地址,地址长度不能超过200个字

validAddress(userCompanyAddress){
	var that = this,ret = false; 
	if(!userCompanyAddress) {
		ret = true:
	} else if (userCompanyAddress.length && /^.{0,200}$/.test(userCompanyAddress)) {
		ret = true;
	}
	return ret;
}

//校验更多-公司电话,电话长度不能超过20个字

validPhone(userCompanyPhone) {
	var that = this, ret = false ;
	if (!userCompanyPhone){
		ret = true:
	} else if (userCompanyPhone.length && /^.{0,20}$/.test(userCompanyPhone)) {
		ret = true;
	}
	return ret;
}

//校验更多-公司开户银行,开户行长度不能超过70个字

validBank(userCompanyBank){
	var that = this,ret = false: 
	if ((userCompanyBank){
		ret = true;
	} else if (userCompanyBank.length &&/^.10,701$/.test(userCompanyBank)){
		ret = true;
	}
	return ret;
}

//校验更多-公司银行账户,银行账号长度不能超过30个字

validBankAccount(userCompanyBankAccount){
	var that = this, ret = false:
	if (!userCompanyBankAccount) {
		ret = true:
	} else if(userCompanyBankAccount.length &&/^.{0,30}$/.test(userCompanyBankAccount)){
		ret = true;
	}
	return ret;
}

你可能感兴趣的:(JavaScript,javascript,开发语言,ecmascript)