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

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

效果:


一、如果有多个文号:

html 复制代码
<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>
typescript 复制代码
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, '');
}
				

二、单个文号:

html 复制代码
<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>
typescript 复制代码
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, '');
}
相关推荐
hdsoft_huge6 分钟前
Java & Spring Boot常见异常全解析:原因、危害、处理与防范
java·开发语言·spring boot
风中的微尘22 分钟前
39.网络流入门
开发语言·网络·c++·算法
前端君30 分钟前
实现最大异步并发执行队列
javascript
未来之窗软件服务1 小时前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
小冯记录编程1 小时前
C++指针陷阱:高效背后的致命危险
开发语言·c++·visual studio
1uther2 小时前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
Nan_Shu_6142 小时前
Web前端面试题(2)
前端
知识分享小能手2 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
C_Liu_2 小时前
C++:类和对象(下)
开发语言·c++
coderxiaohan2 小时前
【C++】类和对象1
java·开发语言·c++