awesome ngx mask
npm install alexbrbr-ngx-mask






You can also try our NGX LOADER INDICATOR Download it.
You can also try our NGX COPYPASTE Download it.
This project exists thanks to all the people who contribute. [Contribute].
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
``bash`
$ npm install --save ngx-mask
Import ngx-mask module in Angular app.
`typescript
import {NgxMaskModule} from 'ngx-mask'
export const options: Partial
@NgModule({
(...)
imports: [
NgxMaskModule.forRoot(options)
]
(...)
})
`
Then, just define masks in inputs.
#### Usage
`html`
Also you can use mask pipe
#### Usage
`html`
{{phone | mask: '(000) 000-0000'}}
#### Examples
| mask | example |
| -------------- | -------------- |
| 9999-99-99 | 2017-04-15 |
| 0*.00 | 2017.22 |
| 000.000.000-99 | 048.457.987-98 |
| AAAA | 0F6g |
| SSSS | asDF |
| character |
|-----------|
| / |
| ( |
| ) |
| . |
| : |
| - |
| space |
| + |
| , |
| @ |
##### Usage
`html`
##### Then:
``
Input value: 789-874.98
Masked value: [78]\[987]`typescript`
patterns ({ [character: string]: { pattern: RegExp, optional?: boolean})
We have next default patterns:
| code | meaning |
| ----- | ------------------------------------------- |
| 0 | digits (like 0 to 9 numbers) |
| 9 | digits (like 0 to 9 numbers), but optional |
| A | letters (uppercase or lowercase) and digits |
| S | only letters (uppercase or lowercase) |
##### Usage:
`html`
and in your component
`typescript`
public customPatterns = {'0': { pattern: new RegExp('\[a-zA-Z\]')}};
##### Then:
``
Input value: 789HelloWorld
Masked value: (Hel-loW)
typescript
pattern = {
'B': {
pattern: new RegExp('\\d'),
symbol: 'X'
}
}
`$3
You can add prefix to you masked value
##### Usage`html
`$3
You can add suffix to you masked value
##### Usage`html
`$3
You can choose if mask will drop special character in the model, or not, default value true
##### Usage`html
`##### Then:
`
Input value: 789-874.98
Model value: 789-874.98
`$3
You can choose if mask is shown while typing, or not, default value false
##### Usage`html
`$3
You can choose clear the input if the input value not match the mask, default value false$3
You can pass array of expression and custom Pattern to pipe
##### Usage`html
{{phone | mask: customMaska}}
`
and in your component
`
customMaska: [string, pattern];pattern = {
'P': {
pattern: new RegExp('\\d'),
}};
this.customMaska = ['PPP-PPP', this.pattern];
`$3
You can pass into mask pattern with brackets
##### Usage`html
`$3
You can devide your input by thousands##### Usage
`html
`
For separate input with dots`html
`
For using decimals enter '.' to the end of your input to 'separator' mask and ',' to 'dot_separator'`html
`
For using decimals enter '.' to the end of your input to 'separator' or 'comma_separator' mask and ',' to 'dot_separator'
`
Input value: 1234.56
Masked value: 1 234.56Input value: 1234,56
Masked value: 1.234,56
Input value: 1234.56
Masked value: 1,234.56
``html
`
For limiting decimal precision add '.' and the precision you want to limit too on the input. 2 is useful for currency. 0 will prevent decimals completely. `
Input value: 1234,56
Masked value: 1.234,56Input value: 1234.56
Masked value: 1,234.56
Input value: 1234,56
Masked value: 1.234
Input value: 1234.56
Masked value: 1,234
`$3
You can validate your input as 24 hour format##### Usage
`html
`$3
You can validate your input for percents##### Usage
`html
`$3
You can validate your formControl, default value is true##### Usage
`html
`
$3
You can hide symbols in input field and get the actual value in formcontrol##### Usage
`html
`$3
##### Usage
`html
``