Logo

vue 正则校验链接

photo
Pastore Antonio

2020年12月06日

1. 

<el-form :model="dataForm" :rules="rules" ref="dataForm" label-width="20px" @keyup.enter.native="dataFormSubmit()">
2.

export default {
  data () {
    let isTrueUrl = (rule, value, callback) => {
      let reg = /(https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/
      if (!reg.test(value)) {
        callback(new Error('请输入正确的链接'))
      } else {
        callback()
      }
    }
    return {
     rules: {
       title: [
        {required: true, message: '请输入标题', trigger: 'blur'},
        { max: 50, message: '标题长度不能超过50个字符', trigger: 'blur' }
       ],
       url: [
        {required: true, message: '请输入链接地址', trigger: 'blur'},
        { validator: isTrueUrl, trigger: 'blur' }
       ]
      }
    }
  }
}
本文为原创文章,请注意保留出处!
修复群晖Synology Drive client右键菜单缺失问题 Local, clean & environmental 作者:Pastore Antonio
1808 浏览量
1785 浏览量
configure: error: Package requirements (oniguruma) were not met Local, clean & environmental 作者:Pastore Antonio
1526 浏览量
Adobe Acrobat Pro 激活 Local, clean & environmental 作者:Pastore Antonio
1522 浏览量
追寻日出,找回自己 Local, clean & environmental 作者:Pastore Antonio
1489 浏览量