Git Product home page Git Product logo

text-mask-vat-id's Introduction

text-mask-vat-id Build Status Coverage Status

Text Mask function for VAT identification number.

Demo available here: dimitrinicolas.github.io/text-mask-vat-id/example

Installation

npm i text-mask-vat-id

Usage

I recommend you to add an uppercase pipe function to text-mask component:

function upperCasePipe(value) {
  return value.toUpperCase();
}

With React.js

import React from 'react'
import MaskedInput from 'react-text-mask'
import createVatIdMask from 'text-mask-vat-id';

const mask = createVatIdMask();

export default () => (
  <MaskedInput
    mask={mask}
    pipe={value => value.toUpperCase()} />
);

In Vanilla JS

<script src="./node_modules/vanilla-text-mask/dist/vanillaTextMask.js"></script>
<script src="./node_modules/text-mask-vat-id/dist/text-mask-vat-id.umd.min.js"></script>
<script>
  function upperCasePipe(value) {
    return value.toUpperCase();
  }

  vanillaTextMask.maskInput({
    inputElement: document.getElementById('vat-input'),
    mask: createVatIdMask(),
    pipe: upperCasePipe
  });
});
</script>

Options

You can pass options as an object when creating text mask:

const mask = createVatIdMask({
  /** options */
});
  • localeFormat (default: false): If the mask should add separation characters ( , -, . and /) to the VAT ID. E.g.: "FR19845015858" would become "FR 19 845 015 858".

Build

Compile with Rollup:

npm run build

Build and test:

npm test

Source

Related

  • text-mask - Input mask for React, Angular, Ember, Vue, & plain JavaScript

License

This project is licensed under the MIT license.

text-mask-vat-id's People

Contributors

dimitrinicolas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dalawwa

text-mask-vat-id's Issues

question: stricter country code mask

This is really helpful work, thank you.

I wonder whether we could enforce a stricter mask while accepting all currently supported formats by changing the following

const COUNTRY_CODE_MASK = [/\w/, /\w/];

to const COUNTRY_CODE_MASK = [/[A-Za-z]/, /[A-Za-z]/].

Then recommend to add a pipe to uppercase the country code in the README.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.