simple, powerful, vuejs validation.
✨ Example✨
Install
yarn add --dev vuelidation@latest
Include Plugin
import Vue from 'vue';
import Vuelidation from 'vuelidation';
Vue.use(Vuelidation);
Use
<script>
new Vue({
data () {
return {
name: '',
}
},
vuelidation: {
data: {
name: {
required: true,
},
},
},
methods: {
submit () {
if (this.$vuelidation.valid()) {
console.log(`Hello, ${this.name}!`)
}
}
}
})
</script>
<template>
<form>
<input type='text' v-model='name' />
<div v-if='$vuelidation.error("name")'>{{ $vuelidation.error('name') }}</div>
<button type="submit" :disabled="$vuelidation.errors()">Submit</button>
</form>
</template>
{
alphabetic: true,
}
{
alpha: true,
}
{
alphaDash: true,
}
{
alphaSpace: true,
}
{
length: 16,
}
{
between: {
min: 5,
max: 10,
},
}
{
betweenLength: {
min: 8,
max: 20,
},
}
{
decimal: {
points: 2,
},
}
{
email: true,
}
{
includes: ['foo', 'bar'],
}
{
numeric: true,
}
{
required: true,
}
* - the arg is optional.