官术网_书友最值得收藏!

Making a part of the mask optional

Till now, all the examples of input masks have shown that all the characters in a mask are mandatory. It is also possible that you can make a part of the mask optional with the use of the question mark (?) character. Anything listed after the question mark within a mask definition will be treated as an optional input. A common use case is displaying the phone number with an optional extension number, as follows:

<span>Phone Ext</span>
<p-inputMask mask="(999) 999-9999? x99999" [(ngModel)]="optional"
name="optionalmask" placeholder="(999) 999-9999? x99999">
</p-inputMask>

Once the user finishes the input by reaching the question mark character and blurs the component, the rest of the validation will be skipped. That is, the input up to that part won't be erased. For example, phone number inputs, such as (666) 234-5678 and (666) 234-5678? x1230 will be valid inputs for the mask's optional case.

The complete demo application with instructions is available on GitHub at
https://github.com/ova2/angular-development-with-primeng/tree/master/chapter3/inputmask.
主站蜘蛛池模板: 应城市| 杂多县| 淮北市| 乌拉特前旗| 福建省| 桃园市| 仁化县| 曲麻莱县| 乌拉特中旗| 长沙县| 灵台县| 元谋县| 徐汇区| 河池市| 淳化县| 通化县| 金寨县| 上高县| 聊城市| 长兴县| 沅陵县| 海兴县| 西丰县| 深州市| 金塔县| 庆云县| 威远县| 永城市| 连城县| 清徐县| 临高县| 龙南县| 四子王旗| 广平县| 富源县| 连城县| 昌都县| 缙云县| 赫章县| 鸡东县| 咸丰县|