Détail du package

vijay06

JsDaddy39MIT14.2.3

awesome ngx mask

ng2-mask, ngx-mask, ng2, angular-mask

readme

ngx-mask

CI npm npm downloads

npm

GitHub contributors

GitHub stars

You can also try our NGX LOADER INDICATOR. You can also try our NGX COPYPASTE.

You can see the full documentation with examples

Installing

$ npm install --save ngx-mask

Quickstart

Import ngx-mask module in Angular app.

With default mask config options

import { NgxMaskModule, IConfig } from 'ngx-mask'

export const options: Partial<null|IConfig> | (() => Partial<IConfig>) = null;

@NgModule({
  imports: [
    NgxMaskModule.forRoot(),
  ],
})

Passing in your own mask config options

import { NgxMaskModule, IConfig } from 'ngx-mask'

const maskConfig: Partial<IConfig> = {
  validation: false,
};

@NgModule({
  imports: [
    NgxMaskModule.forRoot(maskConfig),
  ],
})

Or using a function to get the config:

const maskConfigFunction: () => Partial<IConfig> = () => {
  return {
    validation: false,
  };
};

@NgModule({
  imports: [
    NgxMaskModule.forRoot(maskConfigFunction),
  ],
})

Then, just define masks in inputs.

Usage

<input type="text" mask="<here goes your mask>" />

or

<input type="text" [mask]="<here goes a reference to your component's mask property>" />

Also, you can use mask pipe.

Usage

<span>{{phone | mask: '(000) 000-0000'}}</span>

For separator you can add thousandSeparator

Usage

<span>{{value | mask: 'separator':','}}</span>

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
UUUU ASDF
LLLL asdf

Mask Options

You can define your custom options for all directives (as object in the mask module) or for each (as attributes for directive). If you override this parameter, you have to provide all the special characters (default one are not included).

specialCharacters (string[ ])

We have next default characters:

character
-
/
(
)
.
:
space
+
,
@
[
]
"
'

Usage

<input type="text" [specialCharacters]="[ '[' ,']' , '\\' ]" mask="[00]\[000]" />
Then
Input value: 789-874.98
Masked value: [78]\[987]
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)
U only letters uppercase
L only letters lowercase
Usage
<input type="text" [patterns]="customPatterns" mask="(000-000)" />

and in your component

public customPatterns = { '0': { pattern: new RegExp('\[a-zA-Z\]')} };
Then
Input value: 789HelloWorld
Masked value: (Hel-loW)

Custom pattern for this

You can define custom pattern and specify symbol to be rendered in input field.

pattern = {
  B: {
    pattern: new RegExp('\\d'),
    symbol: 'X',
  },
};

prefix (string)

You can add prefix to you masked value

Usage

<input type="text" prefix="+7" mask="(000) 000 00 00" />

suffix (string)

You can add suffix to you masked value

Usage

<input type="text" suffix="$" mask="0000" />

dropSpecialCharacters (boolean | string[])

You can choose if mask will drop special character in the model, or not, default value is true.

Usage

<input type="text" [dropSpecialCharacters]="false" mask="000-000.00" />
Then
Input value: 789-874.98
Model value: 789-874.98

showMaskTyped (boolean)

You can choose if mask is shown while typing, or not, default value is false.

Usage

<input mask="(000) 000-0000" prefix="+7" [showMaskTyped]="true" />

allowNegativeNumbers (boolean)

You can choose if mask will allow the use of negative numbers. The default value is false.

Usage

<input type="text" [allowNegativeNumbers]="true" mask="separator.2" />
Then
Input value: -10,000.45
Model value: -10000.45

placeHolderCharacter (string)

If the showMaskTyped parameter is enabled, this setting customizes the character used as placeholder. Default value is _.

Usage

<input mask="(000) 000-0000" prefix="+7" [showMaskTyped]="true" placeHolderCharacter="*" />

clearIfNotMatch (boolean)

You can choose clear the input if the input value not match the mask, default value is false.

Pipe with mask expression and custom Pattern ([string, pattern])

You can pass array of expression and custom Pattern to pipe.

Usage

<span>{{phone | mask: customMask}}</span>

and in your component

customMask: [string, pattern];

pattern = {
  P: {
    pattern: new RegExp('\\d'),
  },
};

this.customMask = ['PPP-PPP', this.pattern];

Repeat mask

You can pass into mask pattern with brackets.

Usage

<input type="text" mask="A{4}" />

Thousand separator

You can divide your input by thousands, by default will seperate with a space.

Usage

<input type="text" mask="separator" />

For separate input with dots.

<input type="text" mask="separator" thousandSeparator="." />

For using decimals enter . and how many decimals to the end of your input to separator mask.

<input type="text" mask="separator.2" />
Input value: 1234.56
Masked value: 1 234.56

Input value: 1234,56
Masked value: 1.234,56

Input value: 1234.56
Masked value: 1,234.56
<input type="text" mask="separator.2" thousandSeparator="." />
<input type="text" mask="separator.2" thousandSeparator="," />
<input type="text" mask="separator.0" thousandSeparator="." />
<input type="text" mask="separator.0" thousandSeparator="," />

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,56

Input value: 1234.56
Masked value: 1,234.56

Input value: 1234,56
Masked value: 1.234

Input value: 1234.56
Masked value: 1,234
<input type="text" mask="separator.2" separatorLimit="1000" />

For limiting the number of digits before the decimal point you can set separatorLimit value to 10, 100, 1000 etc.

Input value: 12345678,56
Masked value: 1.234,56

Time validation

You can validate your input as 24 hour format.

Usage

<input type="text" mask="Hh:m0:s0" />

Date validation

You can validate your date.

Usage

<input type="text" mask="d0/M0/0000" />

leadZeroDateTime (boolean)

If the leadZeroDateTime parameter is true, skipped symbols of date or time will be replaced by 0. Default value is false.

Usage

<input type="text" mask="d0/M0/0000" [leadZeroDateTime]="true" />
Input value: 422020
Masked value: 04/02/2020
<input type="text" mask="Hh:m0:s0" [leadZeroDateTime]="true" />
Input value: 777
Masked value: 07:07:07

Percent validation

You can validate your input for percents.

Usage

<input type="text" mask="percent" suffix="%" />

FormControl validation

You can validate your formControl, default value is true.

Usage

<input type="text" mask="00 00" [validation]="true" />

Secure input

You can hide symbols in input field and get the actual value in formcontrol.

Usage

<input placeholder="Secure input" [hiddenInput]="true" mask="XXX/X0/0000" />

IP valid mask

Usage

<input mask="IP" />

CPF_CNPJ valid mask

Usage

<input mask="CPF_CNPJ" />

Dynamic valid mask

Usage

You can pass into mask pattern with ||.

<input mask="000.000.000-00||00.000.000/0000-00" />
<input mask="(00) 0000-0000||(00) 0 0000-0000" />

Function maskFilled

Usage

<input mask="0000" (maskFilled)="maskFilled()" />

changelog

14.2.3(2022-09-16)

Fix

14.2.2(2022-09-13)

Fix

14.2.1(2022-09-11)

Fix

  • package build process

14.2.0(2022-09-11)

Fix

  • update ng 14.2.1
  • Fix (#1029)

14.0.3(2022-06-21)

Fix

14.0.2(2022-06-09)

14.0.1(2022-06-06)

14.0.0(2022-06-05)

Feature

  • Update to Angular 14

13.1.15(2022-05-29)

Fix

13.1.14(2022-05-17)

Fix

13.1.13(2022-05-09)

Fix

13.1.12(2022-04-27)

Fix

  • Fixed issue where active elements within a shadowRoot would not be found by mask
  • Fix (#909)

13.1.11 (2022-04-25)

Fix

13.1.10 (2022-04-18)

Fix

13.1.9 (2022-04-13)

Fix

13.1.8 (2022-04-08)

Feature

  • Added lowercase and uppercase mask support
  • Feature (#947)

13.1.6 (2022-04-04)

Fix

  • Ghost characters shown in input when toggling mask on/off
  • Fix (#897)

13.1.5 (2022-04-03)

Fix

13.1.4 (2022-03-30)

Feature

  • Function maskFilled is added
  • Feature (#917)

13.1.3 (2022-03-28)

Features and fixes

feature (#940) Fixed (#965)

13.1.2 (2022-01-20)

Features

  • added triggerOnMaskChange, allow mask change to trigger onChange

13.1.1 (2022-01-12)

Fixes

  • Revision for separator logic.
  • Set default decimalMarker to [".",","] instead "."

13.1.0 (2021-12-30)

Features

  • Enable non-zero-selections
  • Deletion of special mask character moves just the cursor instead of deleting the character next to it

Test/CI fixes

  • Enable cypress component testing

13.0.1 (2021-12-15)

Test/CI fixes

  • the same that in 13.0.0
  • fix test
  • fix CI

13.0.0 (2021-11-28)

Angular 13 release

  • up all dependencies to latest
  • move from tslint to eslint
  • add more strict rules for tsconfig and code quality config
  • build library with IVY and new angular package structure

12.0.0 (2021-05-19)

Bug Fixes

Fixed (#875) Fixed (#892) Fixed (#861) Fixed (#893)

11.1.5 (2020-03-19)

Bug Fixes

Fixed (#864) (#863) (#706)

11.1.4 (2020-11-26)

Bug Fixes

Remove complet mask if part of it is deleted (#831)

11.1.3 (2020-11-25)

Bug Fixes

Now backspace no leaves special characters (#692) (831)

11.1.2 (2020-11-24)

Bug Fixes

DropSpecialCharacters false also should return prefix (#686) (830)

11.1.1 (2020-11-24)

Bug Fixes

Number cast bug. Now if model value number mask should return type number (#791) (#702) (829)

11.1.0 (2020-11-23)

Bug Fixes

Copy paste event should work as expected (#765) (827)

11.0.1 (2020-11-15)

Bug Fixes

Difinition for form control with `{value, disable} should work (#803) (826)

11.0.0 Update to Angular 11

Update to Angular 11

9.1.0 Directive's selector change

Change directive selector to restrict to input and textarea tags

9.0.2 Bugfix

Fix for #721 - prevent entering dots when decimal marker is comma

9.0.1 Bugfix

Fix for #715 - mark fields as touched on blur on form fields with an empty mask

Fix for #711 - stop fields being marked as dirty after a form reset

9.0.0 Update to Angular 9

Feature: Library updated to Angular 9

Feature: Can pass empty string for thousandSeparator if do not want any separation

Fix: allowNegativeNumbers works correctly when set as true or false. If false, entering a hyphen will not be allowed

Fix: stop cursor jumping around when mask is set as empty

8.2.0 bugfix and breaking change

Fix for #657 - showMaskTyped option now works correctly when set in the config

Fix for #665 - validateTime mark field as invalid immediately if value is null

Feature: Added new error page for handling 404's, and new bugs page for being a playground for bug fixing

Breaking change: Made validation error return an object named mask. If you were previously checking for a validation error named 'Mask error' then it will need changing to just 'mask'.

8.1.7 bugfix

Fix for #369 - add thousandSeparator to separator pipe

Fix for #381 - add support to negative number in separator mask

8.1.6 bugfix

Fix for #560 - do not overwrite the mask available patterns when patterns attribute passed in value is a falsey value i.e null/undefined/false

Fix for #620 - allow delete button to work when at beginning of input and no prefix exists

Fix for #621 - validation config value now works correctly

8.1.5 bugfix

Fix for #614 - export everything from config

8.1.4 bugfix

Fix for #580 - honour the special characters that user may have specified, and prevent runtime exception occuring

Project folder structure converted over to follow Angular CLI way of libraries

8.1.3 bugfix

Fix for #590 - Problem if prefix last char is not a number

8.1.2 placeholder customisation

Placeholder can now be customised

8.1.1 bugfix

bugs fix

8.1.0 separator update

update separator

8.0.8 bugfix

bugs fix [refs: #554, #580, #582]

8.0.7 bugfix

bugs fix [refs: #579, #576, #561]

8.0.7 update date and time

Update date and time masks [refs: #571, #567, #572, #564, #558, #573]

8.0.4 bugfix

minor bug fixes

8.0.3 cursor

minor bug fixes

7.9.9 cursor

Issues fix

7.9.1 cursor

Bugs fix

7.9.1 cursor

Fix Backspace on empty input causes cursor to jump after entering a value

7.8.6 bugfix

Bugfix

7.8.5 update of returned value type

Fix returned value when input value type is number

7.8.4 decimal

Added decimal percent, fix suffix prevents decimals

7.7.3 polyfill

Added polyfill for IE11

7.7.2 dot_separator

Fix decimals

7.7.1 coma_separator

Readme update

7.7.0 coma_separator

Secure input and bugs fix

7.6.6 coma_separator

Bugs fix

[7.6.4 coma_separator] (2019-03-13)

Bugs fix

[7.6.0 coma_separator] (2019-03-11)

Feature: added default validation

[7.5.0 coma_separator] (2019-03-11)

Bugs fix: fix minutes validation, '-' in separator, decimal part in separator and fix issues with FF/IE

[7.4.6 coma_separator] (2019-02-15)

Fix coma_separator behavior

[7.4.5 dependencies] (2019-02-15)

Update dev and prod dependencies

[7.3.4 decimals values separator] (2019-01-17)

Added coma_separator

[7.3.3 decimals values separator] (2019-01-08)

Added decimals values for separator and dot_separator

[7.3.1 update separator] (2018-12-19)

Now separator can separate by dots

[7.3.0 feature percent] (2018-12-14)

Added validation for percent

[7.2.0 feature 24 hour forma] (2018-12-12)

Added valid 24 hour format mask and update separator

[7.1.0 feature thousand separator] (2018-12-11)

Added new mask that separates number by thousands

[7.0.4 fix multiple mask] (2018-12-11)

Fix multiple mask when you use the same symbols bettwen *

[7.0.3 hotfix] (2018-12-10)

hotfix

[7.0.2 update of sufix] (2018-12-10)

sufix appears while you inputing data

6.5.17 fix of sufix

you can use sufix along with '*'

6.5.16 new specialCharacters 'quotes'

You can used new specialCharacters 'quotes'

6.5.15 support for repeat mask

You can pass into mask pattern with brackets

6.4.14 fixed '*' pattern in maskExpression

Fixed pattern '*'

6.4.13 selection of input value and deletion of it is fixed

You can select and delete value.

6.4.12 pipe with mask expression and custom Pattern

You can pass array of expression and custom Pattern to pipe

6.3.11 fixed mask visable

Fixed when page is loaded the mask is visible

6.3.10 fixed writeValue

Fixed writeValue in directive

6.2.8 support for Mask Pipe/MaskService

Added ability to use MaskPipe/MaskService inside component

6.2.5 support for IE

Added poliffyls for IE

6.2.4 support for mask

Added support for using 'showMaskTyped' property to see mask while typing Resolved issues

6.1.3 update demo, added support, resolved issues

Update of demo version Added support to pass in value of type number or string Resolved issues

6.1.1 support for prefix

Add support for prefix

2.9.5 support for optional character in input '?'

Add [ and ] as defoult symbols for mask

2.9.4 support for optional character in input '?'

Fix shift for cursor and updated all dependencies

2.9.3 support for optional character in input '?'

Add support for optional character in input '?'

2.8.3 support for multicharacter input '*'

Add support for multicharacter input '*'

2.7.3 proprioception-reinforcement

Updated all dependencies and remove usages of rxjs