✅ Simple Form Validation In Vue JS | vee-validate

vee-validate is a form validation library for Vue.js that allows you to validate inputs and build better form user interfaces in a familiar declarative style or using configuration functions.

simple form validation in vue js, vue input validation, vue js form validation with bs simple vue validator, custom validation in vue js, vue js form validation, vuelidate

Features

  • 🍞 Easy: Familiar declarative verification and easy to setup.
  • 🧘‍♀️ Flexible: synchronous, asynchronous, field-level, or form-level validation.
  • ⚡️ FAST: Build faster models faster with an intuitive API and little space.
  • 🏏 MINIMUM: Addresses only complex shape concerns, and gives you complete control over everything else.
  • 😎 Neutral UI: Works with native HTML elements or your favorite UI library components.
  • 🦾 Progressive: Works whether you’re using Vue.js as an incremental improvement or in a
  • complex setup.
    INCLUDED RULES: Companion lib with 25+ rules covering most needs in most web applications.
  • 🌐 i18n: 45+ inline grammar sites contributed by developers from around the world.

How to make use of it:

Install and download:

# Yarn
$ yarn add vee-validate@next

# NPM
$ npm i vee-validate@next --save

1. Import and register field and form components.

import { Field, Form } from 'vee-validate';
export default {
  components: {
    Field,
    Form,
  },
  // ...
};

2. Apply a basic required validator to a form field.

<Form v-slot="{ errors }">
  <Field name="field" :rules="isRequired" />
  <span>{{ errors.field }}</span>
</Form>
export default {
  components: {
    Field,
    Form,
  },
  methods: {
    isRequired(value) {
      return value ? true : 'This field is required';
    },
  },
};

3. You can also use the following configuration functions to validate the model.

import { useField } from 'vee-validate';
export default {
  setup() {
    function isRequired(value) {
      if (value && value.trim()) {
        return true;
      }
      return 'This is required';
    }
    const { errorMessage, value } = useField('fieldName', isRequired);
    return {
      errorMessage,
      value,
    };
  },
};
<template>
  <div>
    <input v-model="value" type="text" />
    <span>{{ errorMessage }}</span>
  </div>
</template>
// form-level validation
import { useForm, useField } from 'vee-validate';
export default {
  setup() {
    // Define a validation schema
    const simpleSchema = {
      email(value) {
        // validate email value and return messages...
      },
      name(value) {
        // validate name value and return messages...
      },
    };
    // Create a form context with the validation schema
    useForm({
      validationSchema: simpleSchema,
    });
    // No need to define rules for fields
    const { value: email, errorMessage: emailError } = useField('email');
    const { value: password, errorMessage: passwordError } = useField('password');
    return {
      email,
      emailError,
      password,
      passwordError,
    };
  },
};
<template>
  <div>
    <input name="email" v-model="email" />
    <span>{{ emailError }}</span>
    <input name="password" v-model="password" type="password" />
    <span>{{ passwordError }}</span>
  </div>
</template>

Simple Vue.js Input Validation Plugin, vee-validate Github, vuelidate custom validation example


See Demo And Download

Official Website(logaretm): Click Here

This superior jQuery/javascript plugin is developed by logaretm. For extra Advanced usage, please go to the official website.

Related Posts

HStack-and-VStack-in-CSS

CSS Layout Components Horizontal/Vertical Stack | HStack and VStack

HStack and VStack in CSS – CSS layout components that (basically) stack anything horizontally and vertically. A pure CSS library that makes it easy to stack elements…

Floating-Whatsapp-Chat-Button

How to Add Floating Whatsapp Chat Button In HTML | venom-button

Venom Button is a very simple plugin for the jQuery floating WhatsApp button. Adds a floating button to your site that calls WhatsApp Click to Chat API. It will automatically start the WhatsApp…

Data-Table-Generator-Tabulator

Interactive Data Table Generator with JS/jQuery and JSON | Tabulator

Tabulator allows you to create interactive tables in seconds from any HTML Table, JavaScript array, AJAX data source, or JSON format data. Just include the library in your…

alert-confirm-prompt-attention-js

Simple Alert, Confirm, Prompt Popup Using Vanilla JavaScript Library | attention.js

JavaScript provides various built-in functionality to display popup messages for different purposes. Attention JS is a vanillaJS plugin used to create a custom alert, confirm, or Prompt…

Bootstrap-4-Sidebar-Menu-Responsive-Template

Bootstrap 4 Sidebar Menu Responsive Template | MDB

Bootstrap Side Navbar – Responsive sidebar template based on the Bootstrap 4 framework. An easy-to-use, totally responsive, Google Material Design impressed aspect navigation for modern web app…

Bootstrap-4-Toast-Notification-Plugin

Lightweight Bootstrap 4 Toast Notification Plugin | BS4 Advanced Toast

A lightweight Bootstrap 4 Toast Notification plugin integrated with JS/jQuery. bs4-toast.js is a JavaScript library that enhances the native Bootstrap toast component with icons, buttons, callbacks, and…

Leave a Reply

Your email address will not be published. Required fields are marked *