ts-input-mask
is a TypeScript library allowing to format user input on the fly.
Based on RadMadRobot's Input Mask Library
- International phone numbers:
+1 ([000]) [000] [00] [00]
- Local phone numbers:
([000]) [000]-[00]-[00]
- Names:
[A][-----------------------------------------------------]
- Text:
[A…]
- Dates:
[00]{.}[00]{.}[9900]
- Serial numbers:
[AA]-[00000099]
- IPv4:
[099]{.}[099]{.}[099]{.}[099]
- Visa card numbers:
[0000] [0000] [0000] [0000]
- MM/YY:
[00]{/}[00]
Example of custom notations usage can be found in custom notations test
npm install ts-input-mask --save
var MaskedTextChangedListener = require('ts-input-mask');
//es6
import { MaskedTextChangedListener } from 'ts-input-mask';
const listener: MaskedTextChangedListener = MaskedTextChangedListener.installOn(
primaryFormat, \\ format of mask: +7 ([000]) [000]-[00]-[00]
input, \\ pass HTMLInputElement here document.createElement("input") to attach the listener
new class implements MaskedTextChangedListener.ValueListener {
public onTextChanged( \\ method called when value changes
maskFilled: boolean, \\ true when mask is filled
extractedValue: string, \\ text without placeholder: 1234567890
formattedText: string \\ text with placeholder +7 (123) 456-78-90
): void {
console.log(maskFilled, extractedValue, formattedText);
}
}(),
affineFormats,
customNotations,
affinityCalculationStrategy,
autocomplete
);
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
npm run test
npm run test:coverage
This project is licensed under the MIT License
- RadMadRobot's Android Input Mask Library
- RadMadRobot's iOS Input Mask Library
- input-mask-angular Simple implementation of this library as angular directive