/**
* 匹配端口号
* @param rule
* @param value
* @param callback
* @returns {*}
*/
export const port = (rule, value, callback) => {
if (value) {
const port = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/
if (!port.test(value)) {
return callback(new Error('请输入正确的端口'))
}
}
callback()
}
/**
* 匹配格式:ip或域名
* @param rule
* @param value
* @param callback
* @returns {*}
*/
export const ipDomain = (rule, value, callback) => {
if (value) {
const ipv4 = new RegExp('^' + ipv4Regex + '$')
const ipv6 = new RegExp('^' + ipv6Regex + '$')
const domain = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/
if (!ipv4.test(value) && !ipv6.test(value) && !domain.test(value)) {
callback(new Error('格式不正确'))
}
}
callback()
}