我正在尝试格式化文本框,以便当用户输入电话号码时,它会自动将其放入以下格式:(999)999-9999
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
我尝试使用 MaskedEditExtender,它可以工作,但与我需要的完全相反.
i tried using the MaskedEditExtender, it works but it does the complete opposite of what i need.
当我点击该字段时,它会显示正确的格式,但是一旦我将鼠标移开,它仍然只显示 9999999999
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"/> 推荐答案要回答您的问题,您必须在扩展器上将ClearMaskOnLostFocus"设置为 false 以使蒙版始终显示.
To answer your question, you have to set the "ClearMaskOnLostFocus" to false on the extender for the mask to show all the time.
话虽如此....
我强烈建议您使用 jquery 替代方案.
I strongly suggest that you use the jquery alternative.
digitalbush/projects/masked-input-plugin/
我之所以这么说是因为 maskededitextender 在 safari 中不起作用.
The reason I say this is because the maskededitextender does not work in safari.
更多推荐
屏蔽电话号码的文本框视图
发布评论