屏蔽电话号码的文本框视图 [英] Mask Textbox view for a phone number

查看:29
本文介绍了屏蔽电话号码的文本框视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试格式化文本框,以便当用户输入电话号码时,它会自动将其放入以下格式:(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.

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

我之所以这么说是因为 maskededitextender 在 safari 中不起作用.

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

这篇关于屏蔽电话号码的文本框视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆