Mask Textbox view for a phone number

人盡茶涼 提交于 2019-12-04 01:32:55

问题


i am trying to format a text box so that when the users can type in a phone number and it would automatically put it in the following format :(999)999-9999

i tried using the MaskedEditExtender, it works but it does the complete opposite of what i need.

when i click on the field it shows the correct format, but once i mouse out it still only shows 9999999999

how can i do it so that the user ONLY types in numbers and it puts dashes and parentheses where it's supposed to automatically(which it does now), but keep the format when i click out of it.

<asp:TextBox ID="txtSuperPhone" runat="server" CssClass="myinputstyle"  />
    <asp:MaskedEditExtender ID="mskSuperPhone" runat="server" TargetControlID="txtSuperPhone" Mask="(999)999-9999"/>

回答1:


To answer your question, you have to set the "ClearMaskOnLostFocus" to false on the extender for the mask to show all the time.

That being said....

I strongly suggest that you use the jquery alternative.

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

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




回答2:


Try this

The propoerty "ClearMaskOnLostFocus" 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>


来源:https://stackoverflow.com/questions/18258709/mask-textbox-view-for-a-phone-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!