2.0.4 • Published 9 months ago

@vuelidate/validators v2.0.4

Weekly downloads
3,243
License
MIT
Repository
github
Last release
9 months ago

Vuelidate Validators

This is the standalone validators package for Vuelidate.

Installation

You need to install both this package and Vuelidate.

npm install @vuelidate/core @vuelidate/validators

or with yarn

yarn add @vuelidate/core @vuelidate/validators

Usage

After adding the Vuelidate plugin, you can use the validators by importing them directly. These validators come with error messages out of the box.

import { required, email } from '@vuelidate/validators'

export default {
  data: () => ({
    name: '',
    email: ''
  }),
  validations: {
    name: { required },
    email: { required, email }
  }
}

Raw, no message validators

If you want to use validators without error messages, you can import the raw validators.

import { required, email } from '@vuelidate/validators/dist/raw.esm'

Extending a validator with custom message

You can attach a validation message to a validator via tha withMessage method.

import { common, required } from '@vuelidate/validators'

const requiredWithMessage = common.withMessage(required, 'This field is required and must be filled in')

export default {
  ...,
  validations: {
    name: { requiredWithMessage }
  }
}

Attaching extra data to a validator

If you want to attach extra data properties to validator, so you can use them in the messages and when validating, use the withParams helper.

import { common } from '@vuelidate/validators'

const atLeast = (number) => common.withParams({ number }, (value) => value.length <= number) // just an example

export default {
  ...,
  validations: {
    name: { atLeast: atLeast(5) }
  }
}

Combining params and messages

You can combine both helpers to build a validator.

import { common } from '@vuelidate/validators'

const customMinLength = (number) => common.withMessage((value) => value.length <= number, ({ $params }) => `The field must be at least ${$params.number} chars long`)
const atLeast = (number) => common.withParams({ number }, customMinLength(number)) // just an example

export default {
  ...,
  validations: {
    name: { atLeast: atLeast(5) }
  }
}

Development

To test the package run

yarn test:unit

To link the package run

yarn link

To build run the package, run:

npm run build
@hovrcat/translatorvue-isc-library@prefix/studio-editornboard-uicarbon-zerocarbon-zero-web-widgetcarbon-zero-widget_simonpersonal-zer0personal-zerotest-package-vue@everything-registry/sub-chunk-995mui-vue3@webitel/ui-sdk@wmfs/json-to-vuelidate@wntr/lx-ui@actindo/core-ui@1doc3/hermes-chat@23zane/vue-validator@zdzcode/zc-web-vuejs-core@zalastax/nolb-_vuel@konnec/vue-eloquentadata-ui-v2@vision-aura/vue-core@vivaconagua/vueca@visitscotland/component-library@visitscotland/component-library-export@visitscotland/vs-component-libraryagrobank-corehyshan-form-validation@shopware-pwa/default-theme@shopware-pwa/cms-base@timcowebapps/vue-auth@timcowebapps/vue-uikitapp-my-librarybest-moduleskitaokitao-components@apatheticwes/validationkafka-uikodama-ui@rwapp/quasar-app-extension-vue-core-v2lits-vue-elements@dargmuesli/nuxt-viobasis-vuei18n-validatorsmlrdev-vue3-library@craterapp/vue-sdk@craydel-v3/craydel-password-field@craydel-v3/craydel-text-field@craydel-v3/craydel-textarea@craydel-v3/craydel-autocomplete@craydel-v3/craydel-date-picker@craydel-v3/craydel-date-range-picker@craydel-v3/craydel-file-input@creatiwity/formbuilder@chargetrip/vue3-components@chronicstone/vue-sweetforms@chronicstone/vue-sweettools@choosemycompany/cmc-componentsbra-buttoncarbon-zero-widgetcarbon-zero-widget_stagingccp-ui-kitccp-ui-librarylinks-vue-frameworkjarch-vueplxnnersevenlab-boilerplate-appstory-kit-t2story-kit-t3starter-vuereuni-componentssn-form-make-vue3songtracker-proquasar-app-extension-quasar-validate-rulesquasar-app-extension-villequasar-app-extension-vuelidate-rulesquasar-ui-villeradsqx-efedittaas-base-componentssushil-component-libsushil-viewer-vuetest-mlr-libraryvuelidate-validators-javuefrontvuefront-moonomen-themevue-experience-componentswertyz-vuevue-sdzvue-perfect-authvvalidationvue-ui-kit-basicvi-form-buildervcs2-nuxt-module-2test-ui-waaavillevue-bootstrap-login@itron/makeoverdsc-vue-one@infinitebrahmanuniverse/nolb-_vuel
2.0.4

9 months ago

2.0.3

11 months ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0-alpha.32

2 years ago

2.0.0

2 years ago

2.0.0-alpha.31

2 years ago

2.0.0-alpha.30

2 years ago

2.0.0-alpha.29

2 years ago

2.0.0-alpha.28

2 years ago

2.0.0-alpha.27

2 years ago

2.0.0-alpha.26

2 years ago

2.0.0-alpha.25

3 years ago

2.0.0-alpha.24

3 years ago

2.0.0-alpha.23

3 years ago

2.0.0-alpha.22

3 years ago

2.0.0-alpha.21

3 years ago

2.0.0-alpha.20

3 years ago

2.0.0-alpha.19

3 years ago

2.0.0-alpha.18

3 years ago

2.0.0-alpha.17

3 years ago

2.0.0-alpha.16

3 years ago

2.0.0-alpha.15

3 years ago

2.0.0-alpha.14

3 years ago

2.0.0-alpha.13

3 years ago

2.0.0-alpha.12

3 years ago

2.0.0-alpha.11

3 years ago

2.0.0-alpha.10

3 years ago

2.0.0-alpha.9

3 years ago

2.0.0-alpha.8

3 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.6

3 years ago

2.0.0-alpha.5

4 years ago

2.0.0-alpha.4

4 years ago

2.0.0-alpha.3

4 years ago

2.0.0-alpha.2

4 years ago

2.0.0-alpha.1

4 years ago

2.0.0-alpha.0

4 years ago

1.0.0-alpha.2

5 years ago