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

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

效果:


一、如果有多个文号:

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, '');
}
相关推荐
索迪迈科技5 分钟前
STL库——map/set(类函数学习)
开发语言·c++·学习
Apifox6 分钟前
如何让 Apifox 发布的在线文档具备更好的调试体验?
前端·后端·测试
咔咔一顿操作9 分钟前
【CSS 3D 交互】打造沉浸式 3D 照片墙:结合 JS 实现拖拽交互
前端·javascript·css·3d·交互·css3
0x00012 分钟前
Uniapp - 自定义 Tabbar 实现
前端·uni-app
用户4582031531714 分钟前
Flexbox布局上手:10分钟告别垂直居中难题
前端·css
牛蛙点点申请出战15 分钟前
仿微信语音 WaveView 实现
android·前端·ios
yiyesushu16 分钟前
react + next.js + ethers v6 项目实例
前端
明远湖之鱼17 分钟前
巧用 Puppeteer + Cheerio:批量生成高质量 Emoji 图片
前端·爬虫·node.js
落笔忆梦19 分钟前
利用浏览器空闲时间优化资源加载与渲染
前端·javascript
艾小码20 分钟前
还在用Vue 2硬撑?升级Vue 3的避坑指南来了!
前端·javascript·vue.js