- Angular UI Development with PrimeNG
- Sudheer Jonna Oleg Varaksin
- 151字
- 2021-07-15 17:33:02
Mask format options
The mask attribute is mandatory to use for the input mask. The component not only allows the number type, but it also supports alphabetic and alphanumeric characters, so the mask format can be a combination of the following built-in definitions:
- a: Alphabetic character (A-Z,a-z)
- 9: Numeric character (0-9)
- *: Alphanumeric character (A-Z,a-z,0-9)
Let's take an example where we can show the input mask with different mask options based on a radio button selection, as follows:
<div>
<div id="phoneformat" *ngIf="format == 'Option1'">
<span>Phone:</span>
<p-inputMask mask="(999) 999-9999" [(ngModel)]="phone"
placeholder="(999) 999-9999" name="phone">
</p-inputMask>
</div>
<div id="dateformat" *ngIf="format == 'Option2'">
<span>Date:</span>
<p-inputMask mask="99/99/9999" [(ngModel)]="date"
placeholder="99/99/9999" name="date">
</p-inputMask>
</div>
<div id="serialformat" *ngIf="format == 'Option3'">
<span>Serial Number:</span>
<p-inputMask mask="a*-999-a999" [(ngModel)]="serial"
placeholder="a*-999-a999" name="serial">
</p-inputMask>
</div>
</div>
As per the preceding example, only one input element will be displayed with the defined mask. The following screenshot shows a snapshot result of the mask format for a date:

The unmask attribute can be used to control masked or unmasked output for the value bounded. For instance, it is useful if ngModel sets either a raw unmasked value or a formatted mask value to the component's bound value.
推薦閱讀
- Advanced Machine Learning with Python
- Spring 5.0 By Example
- Learning C# by Developing Games with Unity 2020
- Android Application Development Cookbook(Second Edition)
- BeagleBone Media Center
- PHP網絡編程學習筆記
- STM32F0實戰:基于HAL庫開發
- Unity 2018 Augmented Reality Projects
- 大學計算機基礎
- OpenMP核心技術指南
- 監控的藝術:云原生時代的監控框架
- C語言程序設計
- The Statistics and Calculus with Python Workshop
- Visual FoxPro程序設計實驗教程
- C++ Data Structures and Algorithm Design Principles