资源算法vue-dni

vue-dni

2020-01-19 | |  37 |   0 |   0

Vue DNI Validator

This library is a collection of utilities that allows you to check if a DNI is valid or not and to transform a string to the expected format.

Supported DNIs:

  • Chilean (RUT)

Installation

npm install vue-dni --save# oryarn add vue-dni
import { rutValidator, rutFilter, rutInputDirective } from 'vue-dni';

Usage

This library has three base features: a validator, a filter and a directive.

Validator

The validator checks the passed string and returns a boolean depending on the string's validity as a RUT. We have tested it with vee-validate but it should be usable by any library that uses booleans for validation.

vee-validate Example

component.vue

<script>
  import { ValidationProvider, extend } from "vee-validate";  import { rutValidator } from "vue-dni";  export default {
    name: 'App',
    components: {
      ValidationProvider,
    },    data() {      return {
        rut: null,
      };
    },    created () {      extend("rut", rutValidator);
    }
  }</script>
<template>
  <div>
    <ValidationProvider rules="rut" v-slot="{ errors }">
      <input v-model="rut" type="text" name="rut">
      <span>{{ errors[0] }}</span>
    </ValidationProvider>
  </div>
</template>

vee-validate@2 Example

component.vue

<script>
  import { Validator } from 'vee-validate'
  import { rutValidator } from 'vue-dni'

  export default {
    name: 'App',    created () {      Validator.extend('rut', rutValidator)
    }
  }</script>
<template>
  <input type="text" name="user[rut]" v-validate="'rut'">
  <span v-show="errors.has('user[rut]')">Invalid Rut</span>
</template>

Filter

With the RUT filter you can format any string to appear as a RUT.

import Vue from 'vue';import { rutFilter } from 'vue-dni';Vue.filter('rutFilter', rutFilter);

and then do the render and filtering

{{ user.rut }}<!--  123124124 -->{{ user.rut | rutFilter }}<!--  12.312.412-4 -->

Directive

If you want to format the user input in a text field use the included directive. By default it'll format the string on blur but it can be configured to format while the text is being written.

Rut directive

Rut live directive

import Vue from 'vue';import { rutInputDirective } from 'vue-dni';Vue.directive('rut', rutInputDirective);

And then in your template you can use it like this

<!-- Format on blur --><input type="text" name="user[rut]" v-rut><!-- Format live (while text is being written) --><input type="text" name="user[rut]" v-rut:live>


上一篇:dni-synthetic-gradients

下一篇: DNI_Torch

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...