Package Exports
- string-mask
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-mask) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
#string-mask
A string formatter and validator based on masks.
Installation
With npm
npm install --save string-mask
With bower
bower install --save string-mask
Special mask's characters
Character | Description |
---|---|
0 |
Any numbers |
9 |
Any numbers (Optional) |
# |
Any numbers (recursive) |
A |
Any aphanumeric character Not implemented yet |
a |
Any aphanumeric character (Optional) Not implemented yet |
S |
Any letter |
U |
Any letter (All lower case character will be mapped to uppercase) Not implemented yet |
L |
Any letter (All upper case character will be mapped to lowercase) Not implemented yet |
$ |
Escape character, used to escape any of the special formatting characters. |
Usage
Number
var formatter = new StringMask('#0');
var result = formatter.apply('123'); // 123
Two Decimal number with thousands separators###
var formatter = new StringMask('#.##0,00', {reverse: true});
var result = formatter.apply('100123456'); // 1.001.234,56
result = formatter.apply('6'); // 0,06
Phone number
var formatter = new StringMask('+00 (00) 0000-0000');
var result = formatter.apply('553122222222'); // +55 (31) 2222-2222
Percentage
var formatter = new StringMask('#0,00%');
var result = formatter.apply('001'); // 0,01%
Brazilian CPF number
var formatter = new StringMask('000.000.000-00');
var result = formatter.apply('12965815620'); // 129.658.156-20
Date and time
var formatter = new StringMask('90/90/9900');
var result = formatter.apply('1187'); // 1/1/87