vue-validate

vue-validate is a lightweight validation mixin, by using built-in HTML5 form validation features.

Usage

You have to set name attribute for form elements, you could use like this demo.

<form v-validate="optionalValue">
    ...
</form>
var vm = new Vue({
    el: '#form',
    mixins: [validate(options)],
    methods: {
        submit: function () {
            alert('TODO submit');
        }
    }
});

By default, Validate elements after each input event, You can add the data-lazy="true" attribute to instead sync after change events:

<input type="email" name="email" data-lazy="true">

Vue instances vm expose a property errors and a method valid(selector).

List of built-in validation Rules

Add a custom validation method

Merge one or more methods to options.methods, returning true if an element is valid.

options = {
    // @param bindingValue - The value passed to the directive
    rulename: function (value, elem, param, bindingValue) {
        return boolean;
    }
};

vm.errors

One or more key/value pairs, the value consists of input name, validity state and message:

{
    age: {
        state: 'valueMissing',
        message: 'Please fill out this field.'
    },
    email: {
        state: 'typeMismatch',
        message: "Please include an '@' in the email address. 'a' is missing an '@'."
    }
}

A validity state has the following values:

vm.valid(selector)

Returns true if the selector has no validity problems, false otherwise.

Browser compatibility

https://caniuse.com/#feat=form-validation