How to use the vee-validate.Validator.extend function in vee-validate

To help you get started, we’ve selected a few vee-validate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tencent / bk-cmdb / src / ui / src / common / js / Validator.js View on Github external
return reg.test(value)
    }
}
Validator.extend('http', isHttp)
/*
    长字符
*/
const longchar = {
    getMessage (field, args) { // 错误提示
        return '请输入' + field
    },
    validate: value => { // 验证规则
        return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[\(\)\+\-《》_,,;;“”‘’。\."'\\\/])*$/.test(value)
    }
}
Validator.extend('longchar', longchar)

/*
    短字符
*/
const singlechar = {
    getMessage (field, args) { // 错误提示
        return '请输入' + field
    },
    validate: value => { // 验证规则
        return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[\(\)\+\-《》_,,;;“”‘’。\."'\\\/])*$/.test(value)
    }
}
Validator.extend('singlechar', singlechar)

/*
    更新Validator
github Tencent / bk-cmdb / src / ui / src / common / js / Validator.js View on Github external
}
}
Validator.extend('longchar', longchar)

/*
    短字符
*/
const singlechar = {
    getMessage (field, args) { // 错误提示
        return '请输入' + field
    },
    validate: value => { // 验证规则
        return /^([a-zA-Z0-9]|[\u4e00-\u9fa5]|[\(\)\+\-《》_,,;;“”‘’。\."'\\\/])*$/.test(value)
    }
}
Validator.extend('singlechar', singlechar)

/*
    更新Validator
*/
const dictionary = {
    zh_CN: {
        messages: {
            name: () => '请输入正确的内容',
            longchar: () => '请输入正确的内容',
            singlechar: () => '请输入正确的内容',
            id: () => '格式不正确,只能包含下划线,数字,英文小写',
            http: () => '请输入以http://开头的URL',
            required: (field) => '请输入' + field,
            numeric: (field) => '请输入数字',
            regex: (field) => field + '不合法'
        },
github Tencent / bk-cmdb / src / ui / src / common / js / Validator.js View on Github external
}
Validator.extend('name', isName)
/*
    id
*/
const isID = {
    getMessage (field, args) { // 错误提示
        // zh_CN: field => '请输入' + field
        return '请输入' + field
    },
    validate: value => { // 验证规则
        var reg = /^[a-z0-9_]{1,20}$/
        return reg.test(value)
    }
}
Validator.extend('id', isID)

const isHttp = {
    getMessage (field, args) { // 错误提示
        // zh_CN: field => '请输入' + field
        return '请输入' + field
    },
    validate: value => { // 验证规则
        var reg = /^http:\/\/[^\s]+/
        return reg.test(value)
    }
}
Validator.extend('http', isHttp)
/*
    长字符
*/
const longchar = {
github WeBankPartners / open-monitor / monitor-ui / src / assets / veeValidate / VeeValidate.js View on Github external
: "en-US"),
  messages: null,
  strict: true,
  events: 'blur'
  // events: 'keyup|input|blur'
}

Validator.extend('noEmail', {
  getMessage: () => '格式不正确',
  validate: value => {
    return (/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/gi.test(value))
  }
})


Validator.extend('isIP', {
  getMessage: () => 'ip格式不正确',
  validate: value => {
    return (/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g.test(value))
  }
})

Validator.extend('isNumber', {
  getMessage: () => '输入必须为数字',
  validate: value => {
    return (/^\d{1,}$/.test(value))
  }
})

Vue.use(VeeValidate, config)

export default VeeValidate
github yangan666 / SuperNAT / SuperNAT.Web / manage / src / customValidate.js View on Github external
import { Validator } from "vee-validate"

// Validator.extend("password", {
//   messages: {
//     zh_CN: field => field + "不能少于十位数"
//   },
//   validate: value => {
//     return value
//   }
// })
Validator.extend("confirmPassword", {
  // messages: {
  //   zh_CN: field => "两次输入密码不一致"
  // },
  validate: (val1, val2) => {
    if (val2.lengh > 0) {
      return val1 === val2[0]
    } else {
      return false
    }
  }
})

export default Validator
github NarHakobyan / awesome-vue-boilerplate / src / common / validator.js View on Github external
'use strict';
import { Validator } from 'vee-validate';

Validator.extend('validatePhone', {
    validate: (value, [isPhoneValid]) => {
        return isPhoneValid;
    },
});

Validator.extend('isTermsChecked', {
    validate: value => {
        return value && value === true;
    },
});

Validator.extend('password_regex', {
    validate: value => {
        var strongRegex = new RegExp('^[a-zA-Z0-9!@#$%^&*]*$');
        return strongRegex.test(value);
    },
});

Validator.extend('username_regex', {
    validate: value => {
        var strongRegex = new RegExp("^[a-zA-Z0-9-_']+$");
        return strongRegex.test(value);
    },
});

Validator.extend('text_regex', {
    validate: value => {
        var strongRegex = new RegExp('^\\S+(?: \\S+)*$');
github NarHakobyan / awesome-vue-boilerplate / src / common / validator.js View on Github external
'use strict';
import { Validator } from 'vee-validate';

Validator.extend('validatePhone', {
    validate: (value, [isPhoneValid]) => {
        return isPhoneValid;
    },
});

Validator.extend('isTermsChecked', {
    validate: value => {
        return value && value === true;
    },
});

Validator.extend('password_regex', {
    validate: value => {
        var strongRegex = new RegExp('^[a-zA-Z0-9!@#$%^&*]*$');
        return strongRegex.test(value);
    },
});

Validator.extend('username_regex', {
    validate: value => {
        var strongRegex = new RegExp("^[a-zA-Z0-9-_']+$");
        return strongRegex.test(value);
github NarHakobyan / awesome-vue-boilerplate / src / common / validator.js View on Github external
});

Validator.extend('isTermsChecked', {
    validate: value => {
        return value && value === true;
    },
});

Validator.extend('password_regex', {
    validate: value => {
        var strongRegex = new RegExp('^[a-zA-Z0-9!@#$%^&*]*$');
        return strongRegex.test(value);
    },
});

Validator.extend('username_regex', {
    validate: value => {
        var strongRegex = new RegExp("^[a-zA-Z0-9-_']+$");
        return strongRegex.test(value);
    },
});

Validator.extend('text_regex', {
    validate: value => {
        var strongRegex = new RegExp('^\\S+(?: \\S+)*$');
        return strongRegex.test(value);
    },
});
github logaretm / vee-validate / docs / src / js / components / examples / Backend.vue View on Github external
if (this.emailsDB.indexOf(value) === -1) {
          return resolve({
            valid: true
          });
        }

        return resolve({
          valid: false,
          data: {
            message: `${value} is already taken.`
          }
        });
      }, 200);
    });

    Validator.extend('unique', {
      validate: isUnique,
      getMessage: (field, params, data) => data.message
    });
  },
  methods: {
github lcw2004 / one / one-ui / src / common / utils / init / initVeeValidate.js View on Github external
function attachPasswordRule () {
  Validator.extend('password', {
    getMessage: dictionary.zh_CN.messages.password,
    validate: value => {
      return value.length >= 6 && value.length <= 20
    }
  })
}