[](https://codecov.io/gh/baianat/vee-validate)
[](https://travis-ci.org/baianat/vee-validate)
[](https://www.codacy.com/app/baianat/vee-validate?utm_source=github.com&utm_medium=referral&utm_content=baianat/vee-validate&utm_campaign=Badge_Grade)
[](https://cdnjs.com/libraries/vee-validate/)
[](https://npm-stat.com/charts.html?package=vee-validate)
[](https://www.npmjs.com/package/vee-validate)
[](http://isitmaintained.com/project/baianat/vee-validate "Average time to resolve an issue")
[](http://isitmaintained.com/project/baianat/vee-validate "Percentage of issues still open")
vee-validate is a template-based validation framework for [Vue.js](https://vuejs.org/) that allows you to validate inputs and display errors.
Being template-based you only need to specify for each input what kind of validators should be used when the value changes. The errors will be automatically generated with 40+ locales supported. [Many rules are available out of the box](https://baianat.github.io/vee-validate/guide/rules.html).
This plugin is inspired by [PHP Framework Laravel's validation](https://laravel.com/).
### Installation
#### yarn
```
yarn add vee-validate
```
#### npm
```
npm i vee-validate --save
```
#### CDN
vee-validate is also available on these cdns:
- [jsdelivr cdn](https://cdn.jsdelivr.net/npm/vee-validate@latest/dist/vee-validate.js) [](https://www.jsdelivr.com/package/npm/vee-validate)
- [unpkg](https://unpkg.com/vee-validate)
> When using a CDN via script tag, all the exported modules on VeeValidate are available on the VeeValidate Object. ex: VeeValidate.Validator
### Getting Started
In your script entry point:
```javascript
import Vue from 'vue';
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
```
Now you are all setup to use the plugin.
### Usage
There are two ways to use vee-validate:
#### Using Components (recommended)
Import the `ValidationProvider` component and register it:
```js
import { ValidationProvider } from 'vee-validate';
// Register it globally
// main.js or any entry file.
Vue.component('ValidationProvider', ValidationProvider);
// or register it locally in a component
// mycomponent.vue
export default {
components: {
ValidationProvider
}
};
```
All the JavaScript work is done, let's go to the template and add fields to validate them:
```vue
{{ errors[0] }}
```
The validation provider accepts two props: `rules` which is in its simplest form, a string containing the validation rules seperated by a `pipe` character, and `name` which is the field name that will be used in error messages.
and That's it, your input will be validated automatically, notice that the `ValidationProvider` uses [scoped slots](https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots) to pass down validation state and results.
There is more that can be done! You can customize events, validate initial values, manually validate or reset the field and much more. Make sure to [read the docs](https://baianat.github.io/vee-validate/guide/components.html).
#### Using directive
Apply the `v-validate` directive on your input and pass a **string value** which is a list of validations separated by a pipe. For example, we will use the `required` and the `email` validators:
```vue
```
Now every time the input changes, the validator will run the list of validations from left to right, populating the errors helper object whenever an input fails validation.
To access the errors object (in your vue instance):
```js
this.$validator.errorBag;
// or
this.errors; // injected into $data by the plugin, you can customize the property name.
```
Let's display the error for the email input we've created:
```html
{{ errors.first('email') }}
```
### Documentation
Read the [documentation and demos](https://baianat.github.io/vee-validate/).
### Compatibility
This library uses ES6 Promises so be sure to provide a polyfill for it for the browsers that do not support it.
### Contributing
You are welcome to contribute to this repo, but before you do, please make sure you read the [contribution guide](CONTRIBUTING.md).
### Tutorials and Examples
#### Articles
- [Validation Providers](https://medium.com/@logaretm/vee-validate-validation-providers-b5b38647c05c)
- [Authoring Validatble Vue Components](https://medium.com/@logaretm/authoring-validatable-custom-vue-input-components-1583fcc68314)
- [Vue Multi Step Form](http://statemachine.davestewart.io/html/examples/vue/vue-sign-up.html) by [Dave Stewart](https://github.com/davestewart)
- [An imperative guide to forms in Vue.js](https://blog.logrocket.com/an-imperative-guide-to-forms-in-vue-js-7536bfa374e0) by [Olayinka Omole](https://blog.logrocket.com/@olayinka.omole).
- [Template Driven Form Validation In Vue.js](https://scotch.io/tutorials/template-driven-form-validation-in-vuejs) by [Ogundipe Samuel Ayo](https://twitter.com/fucked_down)
- [Make Validation Great Again! Vue form validation with vee validate](https://qiita.com/nickhall/items/d1043f3f9874c90b6f8e) by [Nick Hall](https://github.com/nickhall)
### Credits
- Some validations/test scenarios are provided/based on [validator.js](https://github.com/chriso/validator.js).
- Inspired by Laravel's [validation syntax](https://laravel.com/docs/5.4/validation).
### license
MIT