Vue中form表單常用rules校驗規則

leepandar發表於2024-04-27

是否合法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();
		}
	}

相關文章