/ Validation

Model data validation library for VueJs

Model data validation library for VueJs


Data Validation Library, for VueJs. Perhaps useful for other libraries/frameworks and other projects, but i created this library and using with VueJs with reactive data.


npm install --save vue-m-validator

Use case

example with components

  • Required the library to your project
import validator from 'vue-m-validator';
  • Make library is reactive
data () {
    return {
      isFirstRun: true,
      username: '',
      email: '',
      password: '',
      password2: '',
      validator: validator
  • If you use many forms on page in a different components, write the hook
  created () {
  • And validate a form

for the 'addRule' method, you should use as an argument the object that should have the following look:

      expression: !USERNAME || USERNAME === ' ',
      name: 'username',
      msg: 'username field required'
  • In a templates you should use v-model for data and validate form data with functions
  • For showing all validation errors you can access the library object property 'errors'
<ul class="form-group">
        v-for="error in validator.errors">
              class="form-text text-muted"
              v-for="msg in error.msgs">
  • To display one group message, use method 'getErrors(name)'
<ul v-if="isUsernameErrors">
        class="form-text text-danger"
        v-for="error in validator.getErrors('username')">
            &nbsp;{{ error }}