Vue中form表单常用rules校验规则

是否合法IP地址

const checkIPCode = (rule, value, callback) => {
		if (/^(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
			.test(value) == false) {
			callback(new Error("请输入正确的ip地址"));
		} else {
			callback();
		}
	}

是否合法端口

const checkPortCode = (rule, value, callback) => {
		if (/^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/.test(value) == false) {
			callback(new Error("请输入正确的端口号"));
		} else {
			callback();
		}
	}
posted @ 2024-04-27 09:48  leepandar  阅读(12)  评论(0编辑  收藏  举报