Skip to content

Lightweight Vue 3 form validation for inputs using zero dependencies (812B gzipped)

Notifications You must be signed in to change notification settings

5e/vue-light-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vue-light-validator

Lightweight Vue 3 form validator using zero dependencies

Features

  • Provides a directive to use validation functions on an input value
  • V-Form wrapper returns a boolean if all inputs are valid
  • Lightweight package which uses no dependencies
  • Easy to use and flexible
<v-form v-model="valid">
      <input v-rules="[rules.required, rules.onlyNumbers]" v-model="phoneNumber" id="phoneNumber" />
      <input v-rules="[rules.required]" v-model="firstName" id="firstName" />
</v-form>
rules: {
    required: (value) => !!value || "Write something",
    onlyNumbers: function (value) {
        let result = /^\d+$/.test(value);
        if (result) {
            return true;
        } else {
            return "Only numbers allowed"
        }
    },
},

//v-form value returns

{
    "valid": false,
    "results": {
        "phoneNumber": "Write something",
        "firstName": true
    }
}

About

Lightweight Vue 3 form validation for inputs using zero dependencies (812B gzipped)

Resources

Stars

Watchers

Forks

Packages

No packages published