<script>
...
methods:{
/**
* 格式校验
* @param value 待校验数据
* @param reg 正则表达式
* @param text 提示文字
* @return {boolean}
*/
checkout(value,reg,text){
let re = new RegExp(reg);
if(value===null || value===''){
this.$message({
type:'warning',
message:'请填写'+text,
duration:5000
})
return false
}else if(!re.test(value)){
this.$message({
type:'warning',
message:'请填写格式正确的'+text,
duration:5000
})
return false
}else{
return true
}
},
/**
* 调用
*/
xxx(){
let regIp = /^(\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])){3}$/
let bool
bool = this.checkout(this.ip,regIp,'ip')
return bool
}
},
...
</script>
Ip格式校验
^(\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])){3}$
Port格式校验
^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$
Mask格式校
^((128|192)|2(24|4[08]|5[245]))(.(0|(128|192)|2((24)|(4[08])|(5[245])))){3}$
Mac格式校验
^[A-Fa-f\d]{2}::[A-Fa-f\d]{2}::[A-Fa-f\d]{2}::[A-Fa-f\d]{2}::[A-Fa-f\d]{2}::[A-Fa-f\d]{2}$
后续继续添加