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

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

效果:


一、如果有多个文号:

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, '');
}
相关推荐
香蕉可乐荷包蛋27 分钟前
Python面试问题
开发语言·python·面试
ErizJ36 分钟前
Golang|分布式索引架构
开发语言·分布式·后端·架构·golang
.生产的驴37 分钟前
SpringBoot 接口国际化i18n 多语言返回 中英文切换 全球化 语言切换
java·开发语言·spring boot·后端·前端框架
八股文领域大手子1 小时前
深入浅出限流算法(三):追求极致精确的滑动日志
开发语言·数据结构·算法·leetcode·mybatis·哈希算法
吃瓜群众i1 小时前
理解Javascript闭包
前端·javascript
安大桃子1 小时前
Mapbox GL + Deck.gl 三维实战:Mapbox 加载 Tileset3D 倾斜摄影模型
前端·webgl
yede1 小时前
多行文本省略号显示,更多按钮展开全部
前端
就是我1 小时前
React 应用性能优化实战
前端·react.js·性能优化
G扇子1 小时前
深入解析XSS攻击:从原理到防御的全方位指南
前端·安全
Blucas1 小时前
《深入 PageSpy》二:入门指南
javascript·前端框架