移动端h5留资页判断(自用)

前提

  • 这里就是简单的姓名电话地址和一个需要勾选的同意项
  • tipShow是我自己写的调用一个提示弹窗的函数,可以换成自己的

代码

//电话号限制11位数
$('.inputPhone').on('input change', function () {
	let phoneContent = $('.inputPhone').val(),
		phoneLength = phoneContent.length;
	if(phoneLength > 11) {
		phoneContent = phoneContent.substr(0,11);
		$('.inputPhone').val(phoneContent);
	}
})

let name = '',
	phone = '',
	address = '',
	agreeInput;
	
//点击留资提交按钮
$('.Pinfo_btn_sure').on('click', function() {
	name = $('.inputName').val();
	phone = $('.inputPhone').val();
	address = $('.inputAddress').val();
	agreeInput = $('.Pinfo_main_checked input[type="checkbox"]:checked').length;
	// console.log('name : ' + name + ' , phone : ' + phone + ' , address : ' + address + ' , agreeInput : ' + agreeInput);

	if (name == '') {
		tipShow('请输入姓名');
	} else if (phone == '' || !(/^1[3456789]\d{9}$/.test(phone))) {
		tipShow('请输入正确手机号');
	} else if (address == '') {
		tipShow('请输入地址');
	} else if (agreeInput != 1) {
		tipShow('请勾选同意项');
	} else {
		console.log('留资成功');
	}
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值