Socket
Socket
Sign inDemoInstall

vuelidate

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuelidate

Simple, lightweight model-based validation for Vue.js


Version published
Maintainers
4
Created

What is vuelidate?

Vuelidate is a simple, lightweight model-based validation library for Vue.js. It allows you to define validation rules for your Vue components and provides a reactive way to handle form validation.

What are vuelidate's main functionalities?

Basic Validation

This code demonstrates basic validation using Vuelidate. It validates that the 'name' field is required and the 'password' field is required and must be at least 6 characters long.

```javascript
import { required, minLength } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';

export default {
  data() {
    return {
      form: {
        name: '',
        password: ''
      }
    };
  },
  validations() {
    return {
      form: {
        name: { required },
        password: { required, minLength: minLength(6) }
      }
    };
  },
  setup() {
    const v$ = useVuelidate();
    return { v$ };
  }
};
```

Custom Validators

This code demonstrates how to create and use a custom validator in Vuelidate. The custom validator checks if the 'email' field contains a valid email address.

```javascript
import { helpers } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';

const customValidator = helpers.withMessage('Must be a valid email', value => /.+@.+\..+/.test(value));

export default {
  data() {
    return {
      form: {
        email: ''
      }
    };
  },
  validations() {
    return {
      form: {
        email: { customValidator }
      }
    };
  },
  setup() {
    const v$ = useVuelidate();
    return { v$ };
  }
};
```

Async Validation

This code demonstrates how to use asynchronous validation in Vuelidate. The async validator checks if the 'username' field is valid by making an API call.

```javascript
import { required } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';

const asyncValidator = helpers.withAsync(async value => {
  const response = await fetch(`https://api.example.com/validate?value=${value}`);
  const result = await response.json();
  return result.isValid;
});

export default {
  data() {
    return {
      form: {
        username: ''
      }
    };
  },
  validations() {
    return {
      form: {
        username: { required, asyncValidator }
      }
    };
  },
  setup() {
    const v$ = useVuelidate();
    return { v$ };
  }
};
```

Other packages similar to vuelidate

FAQs

Package last updated on 08 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc