ngx-mask 16.3.6 → 16.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -424
- package/esm2022/lib/ngx-mask-applier.service.mjs +25 -11
- package/esm2022/lib/ngx-mask.directive.mjs +7 -6
- package/esm2022/lib/ngx-mask.pipe.mjs +3 -3
- package/esm2022/lib/ngx-mask.service.mjs +6 -6
- package/fesm2022/ngx-mask.mjs +38 -23
- package/fesm2022/ngx-mask.mjs.map +1 -1
- package/lib/ngx-mask-applier.service.d.ts +1 -0
- package/lib/ngx-mask.service.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,10 +23,22 @@ You can also try our NGX COPYPASTE [check](https://www.npmjs.com/package/ngx-cop
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
## Installing
|
|
26
|
-
|
|
26
|
+
Angular version 16.x.x
|
|
27
27
|
```bash
|
|
28
28
|
$ npm install --save ngx-mask
|
|
29
29
|
```
|
|
30
|
+
Angular version 15.x.x
|
|
31
|
+
```bash
|
|
32
|
+
$ npm install --save ngx-mask@15.2.1
|
|
33
|
+
```
|
|
34
|
+
Angular version 14.x.x
|
|
35
|
+
```bash
|
|
36
|
+
$ npm install --save ngx-mask@14.3.2
|
|
37
|
+
```
|
|
38
|
+
Angular version 13.x.x or 12.x.x
|
|
39
|
+
```bash
|
|
40
|
+
$ npm install --save ngx-mask@13.2.1
|
|
41
|
+
```
|
|
30
42
|
|
|
31
43
|
## Quickstart if ngx-mask version >= 15.0.0
|
|
32
44
|
|
|
@@ -166,428 +178,8 @@ Then, just define masks in inputs.
|
|
|
166
178
|
|
|
167
179
|
## Usage
|
|
168
180
|
|
|
169
|
-
|
|
170
|
-
<input type="text" mask="<here goes your mask>" />
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
or
|
|
174
|
-
|
|
175
|
-
```html
|
|
176
|
-
<input type="text" [mask]="<here goes a reference to your component's mask property>" />
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Also, you can use mask pipe.
|
|
180
|
-
|
|
181
|
-
```html
|
|
182
|
-
<span>{{phone | mask: '(000) 000-0000'}}</span>
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
You could path any valid config options, for example thousandSeparator and suffix
|
|
186
|
-
|
|
187
|
-
```html
|
|
188
|
-
<span>{{value | mask: 'separator': {thousandSeparator: ',', suffix: ' sm'}}</span>
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Examples
|
|
192
|
-
|
|
193
|
-
| mask | example |
|
|
194
|
-
| -------------- | -------------- |
|
|
195
|
-
| 9999-99-99 | 2017-04-15 |
|
|
196
|
-
| 0\*.00 | 2017.22 |
|
|
197
|
-
| 000.000.000-99 | 048.457.987-98 |
|
|
198
|
-
| AAAA | 0F6g |
|
|
199
|
-
| SSSS | asDF |
|
|
200
|
-
| UUUU | ASDF |
|
|
201
|
-
| LLLL | asdf |
|
|
202
|
-
|
|
203
|
-
## Mask Options
|
|
204
|
-
|
|
205
|
-
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).
|
|
206
|
-
|
|
207
|
-
### specialCharacters (string[ ])
|
|
208
|
-
|
|
209
|
-
We have next default characters:
|
|
210
|
-
|
|
211
|
-
| character |
|
|
212
|
-
| --------- |
|
|
213
|
-
| - |
|
|
214
|
-
| / |
|
|
215
|
-
| ( |
|
|
216
|
-
| ) |
|
|
217
|
-
| . |
|
|
218
|
-
| : |
|
|
219
|
-
| **space** |
|
|
220
|
-
| + |
|
|
221
|
-
| , |
|
|
222
|
-
| @ |
|
|
223
|
-
| [ |
|
|
224
|
-
| ] |
|
|
225
|
-
| " |
|
|
226
|
-
| ' |
|
|
227
|
-
|
|
228
|
-
#### Usage
|
|
229
|
-
|
|
230
|
-
```html
|
|
231
|
-
<input type="text" [specialCharacters]="[ '[' ,']' , '\\' ]" mask="[00]\[000]" />
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
##### Then
|
|
235
|
-
|
|
236
|
-
```text
|
|
237
|
-
Input value: 789-874.98
|
|
238
|
-
Masked value: [78]\[987]
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
patterns ({ [character: string]: { pattern: RegExp, optional?: boolean})
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
We have next default patterns:
|
|
246
|
-
|
|
247
|
-
| code | meaning |
|
|
248
|
-
| ----- | ------------------------------------------- |
|
|
249
|
-
| **0** | digits (like 0 to 9 numbers) |
|
|
250
|
-
| **9** | digits (like 0 to 9 numbers), but optional |
|
|
251
|
-
| **A** | letters (uppercase or lowercase) and digits |
|
|
252
|
-
| **S** | only letters (uppercase or lowercase) |
|
|
253
|
-
| **U** | only letters uppercase |
|
|
254
|
-
| **L** | only letters lowercase |
|
|
255
|
-
|
|
256
|
-
##### Usage
|
|
257
|
-
|
|
258
|
-
```html
|
|
259
|
-
<input type="text" [patterns]="customPatterns" mask="(000-000)" />
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
and in your component
|
|
263
|
-
|
|
264
|
-
```typescript
|
|
265
|
-
public customPatterns = { '0': { pattern: new RegExp('\[a-zA-Z\]')} };
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
##### Then
|
|
269
|
-
|
|
270
|
-
```text
|
|
271
|
-
Input value: 789HelloWorld
|
|
272
|
-
Masked value: (Hel-loW)
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Custom pattern for this
|
|
276
|
-
|
|
277
|
-
You can define custom pattern and specify symbol to be rendered in input field.
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
pattern = {
|
|
281
|
-
B: {
|
|
282
|
-
pattern: new RegExp('\\d'),
|
|
283
|
-
symbol: 'X',
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### prefix (string)
|
|
289
|
-
|
|
290
|
-
You can add prefix to you masked value
|
|
291
|
-
|
|
292
|
-
#### Usage
|
|
293
|
-
|
|
294
|
-
```html
|
|
295
|
-
<input type="text" prefix="+7" mask="(000) 000 00 00" />
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### suffix (string)
|
|
299
|
-
|
|
300
|
-
You can add suffix to you masked value
|
|
301
|
-
|
|
302
|
-
#### Usage
|
|
303
|
-
|
|
304
|
-
```html
|
|
305
|
-
<input type="text" suffix="$" mask="0000" />
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
### dropSpecialCharacters (boolean | string[])
|
|
309
|
-
|
|
310
|
-
You can choose if mask will drop special character in the model, or not, default value is `true`.
|
|
311
|
-
|
|
312
|
-
#### Usage
|
|
313
|
-
|
|
314
|
-
```html
|
|
315
|
-
<input type="text" [dropSpecialCharacters]="false" mask="000-000.00" />
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
##### Then
|
|
319
|
-
|
|
320
|
-
```text
|
|
321
|
-
Input value: 789-874.98
|
|
322
|
-
Model value: 789-874.98
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
### showMaskTyped (boolean)
|
|
326
|
-
|
|
327
|
-
You can choose if mask is shown while typing, or not, default value is `false`.
|
|
328
|
-
|
|
329
|
-
#### Usage
|
|
330
|
-
|
|
331
|
-
```html
|
|
332
|
-
<input mask="(000) 000-0000" prefix="+7" [showMaskTyped]="true" />
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### allowNegativeNumbers (boolean)
|
|
336
|
-
|
|
337
|
-
You can choose if mask will allow the use of negative numbers. The default value is `false`.
|
|
338
|
-
|
|
339
|
-
#### Usage
|
|
340
|
-
|
|
341
|
-
```html
|
|
342
|
-
<input type="text" [allowNegativeNumbers]="true" mask="separator.2" />
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
##### Then
|
|
346
|
-
|
|
347
|
-
```text
|
|
348
|
-
Input value: -10,000.45
|
|
349
|
-
Model value: -10000.45
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### placeHolderCharacter (string)
|
|
353
|
-
|
|
354
|
-
If the `showMaskTyped` parameter is enabled, this setting customizes the character used as placeholder. Default value is `_`.
|
|
355
|
-
|
|
356
|
-
#### Usage
|
|
357
|
-
|
|
358
|
-
```html
|
|
359
|
-
<input mask="(000) 000-0000" prefix="+7" [showMaskTyped]="true" placeHolderCharacter="*" />
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
### clearIfNotMatch (boolean)
|
|
363
|
-
|
|
364
|
-
You can choose clear the input if the input value **not match** the mask, default value is `false`.
|
|
365
|
-
|
|
366
|
-
### Pipe with mask expression and custom Pattern ([string, pattern])
|
|
367
|
-
|
|
368
|
-
You can pass array of expression and custom Pattern to pipe.
|
|
369
|
-
|
|
370
|
-
#### Usage
|
|
371
|
-
|
|
372
|
-
```html
|
|
373
|
-
<span>{{phone | mask: customMask}}</span>
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
and in your component
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
customMask: [string, pattern];
|
|
380
|
-
|
|
381
|
-
pattern = {
|
|
382
|
-
P: {
|
|
383
|
-
pattern: new RegExp('\\d'),
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
this.customMask = ['PPP-PPP', this.pattern];
|
|
388
|
-
```
|
|
181
|
+
Text [documentation](https://github.com/JsDaddy/ngx-mask/blob/develop/USAGE.md)
|
|
389
182
|
|
|
390
|
-
### Repeat mask
|
|
391
183
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
#### Usage
|
|
395
|
-
|
|
396
|
-
```html
|
|
397
|
-
<input type="text" mask="A{4}" />
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
### Thousand separator
|
|
401
|
-
|
|
402
|
-
You can divide your input by thousands, by default will seperate with a space.
|
|
403
|
-
|
|
404
|
-
#### Usage
|
|
405
|
-
|
|
406
|
-
```html
|
|
407
|
-
<input type="text" mask="separator" />
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
For separate input with dots.
|
|
411
|
-
|
|
412
|
-
```html
|
|
413
|
-
<input type="text" mask="separator" thousandSeparator="." />
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
For using decimals enter `.` and how many decimals to the end of your input to `separator` mask.
|
|
417
|
-
|
|
418
|
-
```html
|
|
419
|
-
<input type="text" mask="separator.2" />
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
```text
|
|
423
|
-
Input value: 1234.56
|
|
424
|
-
Masked value: 1 234.56
|
|
425
|
-
|
|
426
|
-
Input value: 1234,56
|
|
427
|
-
Masked value: 1.234,56
|
|
428
|
-
|
|
429
|
-
Input value: 1234.56
|
|
430
|
-
Masked value: 1,234.56
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
```html
|
|
434
|
-
<input type="text" mask="separator.2" thousandSeparator="." />
|
|
435
|
-
<input type="text" mask="separator.2" thousandSeparator="," />
|
|
436
|
-
<input type="text" mask="separator.0" thousandSeparator="." />
|
|
437
|
-
<input type="text" mask="separator.0" thousandSeparator="," />
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
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.
|
|
441
|
-
|
|
442
|
-
```text
|
|
443
|
-
Input value: 1234,56
|
|
444
|
-
Masked value: 1.234,56
|
|
445
|
-
|
|
446
|
-
Input value: 1234.56
|
|
447
|
-
Masked value: 1,234.56
|
|
448
|
-
|
|
449
|
-
Input value: 1234,56
|
|
450
|
-
Masked value: 1.234
|
|
451
|
-
|
|
452
|
-
Input value: 1234.56
|
|
453
|
-
Masked value: 1,234
|
|
454
|
-
```
|
|
455
|
-
```html
|
|
456
|
-
<input type="text" mask="separator.2" [leadZero]="true" />
|
|
457
|
-
```
|
|
458
|
-
To add zeros to the model at the end
|
|
459
|
-
|
|
460
|
-
```text
|
|
461
|
-
Input value: 12
|
|
462
|
-
Masked value: 12.00
|
|
463
|
-
|
|
464
|
-
Input value: 12.1
|
|
465
|
-
Masked value: 12.10
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
```html
|
|
469
|
-
<input type="text" mask="separator.2" separatorLimit="1000" />
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
For limiting the number of digits before the decimal point you can set `separatorLimit` value to _10_, _100_, _1000_ etc.
|
|
473
|
-
|
|
474
|
-
```text
|
|
475
|
-
Input value: 12345678,56
|
|
476
|
-
Masked value: 1.234,56
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
### Time validation
|
|
480
|
-
|
|
481
|
-
You can validate your input as 24 hour format.
|
|
482
|
-
|
|
483
|
-
#### Usage
|
|
484
|
-
|
|
485
|
-
```html
|
|
486
|
-
<input type="text" mask="Hh:m0:s0" />
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
### Date validation
|
|
490
|
-
|
|
491
|
-
You can validate your date.
|
|
492
|
-
|
|
493
|
-
#### Usage
|
|
494
|
-
|
|
495
|
-
```html
|
|
496
|
-
<input type="text" mask="d0/M0/0000" />
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
### leadZeroDateTime (boolean)
|
|
500
|
-
|
|
501
|
-
If the `leadZeroDateTime` parameter is `true`, skipped symbols of date or time will be replaced by `0`. Default value is `false`.
|
|
502
|
-
|
|
503
|
-
#### Usage
|
|
504
|
-
|
|
505
|
-
```html
|
|
506
|
-
<input type="text" mask="d0/M0/0000" [leadZeroDateTime]="true" />
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
```text
|
|
510
|
-
Input value: 422020
|
|
511
|
-
Masked value: 04/02/2020
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
```html
|
|
515
|
-
<input type="text" mask="Hh:m0:s0" [leadZeroDateTime]="true" />
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
```text
|
|
519
|
-
Input value: 777
|
|
520
|
-
Masked value: 07:07:07
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
### Percent validation
|
|
524
|
-
|
|
525
|
-
You can validate your input for percents.
|
|
526
|
-
|
|
527
|
-
#### Usage
|
|
528
|
-
|
|
529
|
-
```html
|
|
530
|
-
<input type="text" mask="percent" suffix="%" />
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
### FormControl validation
|
|
534
|
-
|
|
535
|
-
You can validate your `formControl`, default value is `true`.
|
|
536
|
-
|
|
537
|
-
#### Usage
|
|
538
|
-
|
|
539
|
-
```html
|
|
540
|
-
<input type="text" mask="00 00" [validation]="true" />
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
### Secure input
|
|
544
|
-
|
|
545
|
-
You can hide symbols in input field and get the actual value in `formcontrol`.
|
|
546
|
-
|
|
547
|
-
#### Usage
|
|
548
|
-
|
|
549
|
-
```html
|
|
550
|
-
<input placeholder="Secure input" [hiddenInput]="true" mask="XXX/X0/0000" />
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
### IP valid mask
|
|
554
|
-
|
|
555
|
-
#### Usage
|
|
556
|
-
|
|
557
|
-
```html
|
|
558
|
-
<input mask="IP" />
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
### CPF_CNPJ valid mask
|
|
562
|
-
|
|
563
|
-
#### Usage
|
|
564
|
-
|
|
565
|
-
```html
|
|
566
|
-
<input mask="CPF_CNPJ" />
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
### Allow few mask in one expression
|
|
570
|
-
|
|
571
|
-
#### Usage
|
|
572
|
-
|
|
573
|
-
You can pass into mask pattern with `||`.
|
|
574
|
-
|
|
575
|
-
```html
|
|
576
|
-
<input mask="000.000.000-00||00.000.000/0000-00" />
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
```html
|
|
580
|
-
<input mask="(00) 0000-0000||(00) 0 0000-0000" />
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
```html
|
|
584
|
-
<input mask="00||SS" />
|
|
585
|
-
```
|
|
586
|
-
|
|
587
|
-
### Function maskFilled
|
|
588
|
-
|
|
589
|
-
#### Usage
|
|
590
|
-
|
|
591
|
-
```html
|
|
592
|
-
<input mask="0000" (maskFilled)="maskFilled()" />
|
|
593
|
-
```
|
|
184
|
+
## Contributing
|
|
185
|
+
We would love some contributions! Check out this [document](https://github.com/JsDaddy/ngx-mask/blob/develop/CONTRIBUTING.md) to get started.
|