Money(Currency) Mask Library In Vanilla JavaScript – SimpleMaskMoney

Category: Form , Javascript | April 13, 2018
Author: codermarcos
Views Total: 46
Official Page: Go to website
Last Update: April 13, 2018
License: MIT

Preview:

Money(Currency) Mask Library In Vanilla JavaScript – SimpleMaskMoney

Description:

A vanilla JavaScript input mask library that masks data entry in an input field in the form of money.

Supports custom prefix, suffix, decimal/thousand separators as well as precision.

Also works with Angular, React and Vue.js frameworks.

How to use it:

Import the JavaScript file ‘simple-mask-money.js’ into the document.

<script src="simple-mask-money.js"></script>

Create a numeric input on the page.

<input inputmode="numeric" id="myInput" value="0,00"><br>

Activate the money mask on the input field.

let input = SimpleMaskMoney.setMask('#myInput');

Default configurations to customize the SimpleMaskMoney.

let input = SimpleMaskMoney.setMask('#myInput',{
    prefix: '',
    suffix: '',
    fixed: true,
    fractionDigits: 2,
    decimalSeparator: ',',
    thousandsSeparator: '.',
    autoCompleteDecimal: false,
    emptyOrInvalid: () => {
      return this.SimpleMaskMoney.args.fixed
        ? `0${this.SimpleMaskMoney.args.decimalSeparator}00`
        : `_${this.SimpleMaskMoney.args.decimalSeparator}__`;
    }
});

Leave a Reply