Mask Text box for phone number

I am trying to format a text box so that a user can enter a phone number and he would automatically place it in the following format: (999) 999-9999

I tried to use MaskedEditExtender, it works, but it is completely opposite to what I need.

when I click on the field, it shows the correct format, but as soon as I exit, it still shows only 9999999999

how can I do this so that the user ONLY enters numbers and he puts a dash and parentheses where he should automatically (what he is doing now), but keep the format when I exit it.

<asp:TextBox ID="txtSuperPhone" runat="server" CssClass="myinputstyle" /> <asp:MaskedEditExtender ID="mskSuperPhone" runat="server" TargetControlID="txtSuperPhone" Mask="(999)999-9999"/> 
+4
source share
2 answers

To answer your question, you must set the "ClearMaskOnLostFocus" parameter to false on the expander so that the mask is displayed all the time.

It is said ....

I highly recommend using an alternative to jquery.

http://digitalbush.com/projects/masked-input-plugin/

The reason I say this is because maskededitextender does not work on safari.

+7
source

try it

The "ClearMaskOnLostFocus" proposition must be false.

 <asp:MaskedEditExtender ID="mskSuperPhone" runat="server" TargetControlID="txtSuperPhone" ClearMaskOnLostFocus ="false" MaskType="None" Mask="(999)999-9999" MessageValidatorTip="true" InputDirection="LeftToRight" ErrorTooltipEnabled="True"> </asp:MaskedEditExtender> 
+4
source

Source: https://habr.com/ru/post/1497298/


All Articles