mui、vue 开发混合App表单验证

mui、vue 开发混合App表单验证

最近开发app遇到了表单验证的问题,在网上找了半天,都不是想要的东西。下面是自己写的验证,比较简单,还没有完善。

<div class="form-group">
		<h5 class="mui-content-padded">申请原因 *</h5>
		<input type="text" class="mui-input-clear" v-model="listsource.Description" placeholder="请输入申请原因" />
</div>
<div class="form-group">
		<h5 class="mui-content-padded">访客姓名 *</h5>
		<input type="text" class="mui-input-clear" v-model="listsource.VisitorName" placeholder="请输入访客姓名" />
</div>
const vm = new Vue({
	el: "#content",
	data: {
		listsource: {
			Description: "",
			VisitorName: "",	
	},
	created() {},

	methods: {
		submit(e) {
			if (this.isNotNull() === false) {
				return;
			}
		},
		// 表单验证
		isNotNull() {
			for (let item in this.listsource) {
				if (this.listsource.Description === '') {
					mui.toast('请输入申请原因');
					return false;
				}
				if (this.listsource.VisitorName === '') {
					mui.toast('请输入拜访人姓名');
					return false;
				}
				if (this.listsource.VistorIDCardNo === '' || this.IDCardNoRule(this.listsource.VistorIDCardNo) === false) {
					mui.toast('请输入正确的身份证号');
					return false;
				}
			}
		},
		IDCardNoRule(IdCode) {
			const reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
			if (reg.test(IdCode) === false) {
				mui.toast('请输入正确的身份证号!');
				return false;
			} else {
				return true;
			}
		},
		phoneRule(data) {
			const reg = /^1[3|4|5|7|8][0-9]{9}$/;
			return reg.test(data) === true ? true : false;
		},	
	}
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值