Mask

There are some ready-to-use standard rules:

  • 0 = any digit
  • A = any alphanumeric
  • S = any letter
  • X = any letter and transform to uppercase
  • x = any letter and
  • Z = any alphanumeric and transform to uppercase
  • z = any alphanumeric and transform to lowercase

To use the mask without selecting a field, use mask, unmask methods. These values ​​are not put in a store.

import TsNanoForm from "./nanoForm";

const { getForm } = TsNanoForm
const formUser = getForm("user");
const { mask, unmask } = FormUser;
mask("123456789", "000-000-000");
//123-456-789

unmask("123-456-789");
//123456789

Store Mask

If is necessary to validate these values, put a masked value in a store, use the setMasked methods.

There are also getMasked and getMoneyMasked which returns a masked value without changing the store.

Be careful when using the getUnmasked method, if the value is money use getMoneyUnmasked to add the decimal values.

import TsNanoForm from "./nanoForm";

const { getForm } = TsNanoForm
const formUser = getForm("user");
const { field } = formUser;
const {
  setValue,
  setMoney,
  setMasked,
  setMoneyMasked,
  getValue,
  getMasked,
  getMoneyMasked,
  getMoneyUnmasked,
} = field("document");

setValue("123456");
getMasked("000-000");
//123-456
getValue();
//123456

setMoney("123456");
getMoneyMasked();
//1.234,56
getValue();
//123456

setMasked("789012", "000-000");
getValue();
//789-012

setMoneyMasked("345678");
getValue();
//3.456,78

getMoneyUnmasked();
//3456.78
getUnmasked();
//345678