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

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.
主站蜘蛛池模板: 横山县| 新沂市| 五大连池市| 东山县| 偏关县| 万州区| 文成县| 大荔县| 蛟河市| 白朗县| 太保市| 浙江省| 确山县| 柯坪县| 扬中市| 兴文县| 南投市| 南宫市| 郯城县| 金沙县| 寿阳县| 册亨县| 洞口县| 泰宁县| 广元市| 红河县| 红河县| 布拖县| 丁青县| 麻栗坡县| 库尔勒市| 太白县| 两当县| 宁南县| 九寨沟县| 滁州市| 司法| 巴中市| 东乡| 高州市| 基隆市|