0.1.4 • Published 3 years ago
vue-flex-validator v0.1.4
Vue-Flex-Validator
Vue-flex-validator is a vue plugin used for validating form input... It takes it approach from laravel request validator
Installation
Via npm
npm i vue-flex-validator
In Main.js file
import VueFlexValidator from 'vue-flex-validator'
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App);
app.use(VueFlexValidator);
app.mount('#app')
Usuage
import { inject } from "vue";
export default {
name: "App",
setup() {
const flexValidator = inject("flexValidator");
return {
flexValidator,
};
},
data() {
return {
formData: {
name: "",
email: "",
location: "",
},
};
},
components: {},
methods: {
submit() {
try {
new this.flexValidator(this.formData).check({
name: "required|notNull",
email: "required|notNull|email",
location: "required|min:30",
});
} catch (err) {
console.log(err.message);
}
},
},
};
Validation Rules
Rule | Description |
---|---|
required | input must not be empty |
notNull | Must not be null |
min | Minimum input allowed e.g min:20 |
max | Maximum input allowed e.g max:40 |
Must be a valid email address |
License
MIT
Free Software, Hell Yeah!