Socket
Socket
Sign inDemoInstall

@vuelidate/core

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vuelidate/core

Simple, lightweight model-based validation for Vue.js


Version published
Maintainers
3
Created

What is @vuelidate/core?

@vuelidate/core is a model-based validation library for Vue.js that allows you to define validation rules for your data models. It is designed to be flexible and extensible, making it easy to integrate with your Vue components and manage form validations.

What are @vuelidate/core's main functionalities?

Basic Validation

This code demonstrates how to set up basic validation rules using @vuelidate/core. The `required` and `minLength` validators are imported and applied to the `name` and `password` fields of the form.

```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 shows how to create a custom validator using @vuelidate/core. The `isEven` validator checks if a number is even and provides a custom error message if it is not.

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

const isEven = helpers.withMessage('The value must be even', value => value % 2 === 0);

export default {
  data() {
    return {
      form: {
        number: 0
      }
    };
  },
  validations() {
    return {
      form: {
        number: { isEven }
      }
    };
  },
  setup() {
    const v$ = useVuelidate();
    return { v$ };
  }
};
```

Async Validators

This code demonstrates how to use an asynchronous validator with @vuelidate/core. The `isUniqueUsername` validator checks if a username is unique by making an API call.

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

const isUniqueUsername = async value => {
  const response = await fetch(`/api/check-username?username=${value}`);
  const data = await response.json();
  return data.isUnique;
};

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

Other packages similar to @vuelidate/core

FAQs

Package last updated on 29 Jun 2023

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