文号验证-同时对两个输入框验证

文号验证-同时对两个输入框验证

效果:

在这里插入图片描述
在这里插入图片描述

一、如果有多个文号:

<div v-for="(item, index) in approvalForm.productApprovalTypeEvents" :key="index">
<el-form-item
	label="文号"
	:prop="'productApprovalTypeEvents.' + index"
	:rules="rules.combinedRule"
>
	证监许可〔<el-input v-model="item.noOne" style="width: 30%" clearable @input="handleInputNum($event, 'noOne', index)"></el-input><el-input v-model="item.noTwo" style="width: 30%" clearable @input="handleInputNum($event, 'noTwo', index)"></el-input></el-form-item>
</div>
rules: {
	combinedRule: [
		{ required: true, message: '无效证监许可号', trigger: 'blur' },
		{ validator: combinedRuleValidator, trigger: 'blur' },
	],
}

function combinedRuleValidator(rule: any, value: any, callback: any) {
	// 获取当前表单项对应的对象
	// console.log(value, 'valueeee');
	const noOne = value.noOne;
	const noTwo = value.noTwo;
	if (!noOne || !noTwo) {
		callback(new Error('无效证监许可号'));
	} else {
		callback();
	}
}
// 证监许可号
function handleInputNum(val: string, field: string, fIndex: number) {
	state.approvalForm.productApprovalTypeEvents[fIndex][field] = val.replace(/\D/g, '');
}
				

二、单个文号:

<el-form-item
	v-if="sendInfoForm.apvlFileType == '1' || sendInfoForm.apvlFileType == '2'"
	:label="sendInfoForm.apvlFileType == '1' ? '批复文号' : sendInfoForm.apvlFileType == '2' ? '变更批复文号' : '文号'"
	prop="noOne"
	:rules="rules.combinedRule"
>
	证监许可〔<el-input
		v-model="sendInfoForm.noOne"
		style="width: 35% !important"
		clearable
		@input="handleInputNum($event, 'noOne')"
	></el-input
	><el-input v-model="sendInfoForm.noTwo" style="width: 34% !important" clearable @input="handleInputNum($event, 'noTwo')"></el-input
	></el-form-item>

rules:{
	combinedRule: [
		{ required: true, message: '无效证监许可号', trigger: ['blur', 'change'] },
		{ validator: combinedRuleValidator, trigger: 'blur' },
	],
}
function combinedRuleValidator(rule: any, value: any, callback: any) {
	if (!state.sendInfoForm.noOne && !state.sendInfoForm.noTwo) {
		callback(new Error('无效证监许可号'));
	} else if (!state.sendInfoForm.noOne) {
		callback(new Error('无效证监许可号'));
	} else if (!state.sendInfoForm.noTwo) {
		callback(new Error('无效证监许可号'));
	} else {
		callback();
	}
}
// 证监许可号
function handleInputNum(val: string, field: string) {
	state.sendInfoForm[field] = val.replace(/\D/g, '');
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值