使用屏蔽文本框来验证输入

发布于 2024-10-02 12:52:32 字数 299 浏览 0 评论 0原文

您好,我正在使用以下掩码字符串来确保用户输入有效的电话号码

(99)-00000000,

该电话号码对于澳大利亚的移动电话以及区域固定电话号码应该可以正常工作,

但是我遇到了一个问题,即用户可以在不输入所有电话号码的情况下离开 我知道9

代表 0 到 9 之间的可选数字,0 代表 0 到 9 之间的必需数字

那么,为什么如果我不输入所有最后八个强制数字,程序仍然显示类似

(03)-6474

(03) 的结果- 63799

(02)-1 38 390

Hi I am using the following mask string to ensure user enters a valid phone no

(99)-00000000

which should work fine for mobile as well as regional land line numbers in Australia

However I have encountered a problem that User can get away without entring all the digits

I understand that 9 represents an optional digit between 0 and 9 and 0 represents a required digit between 0 and 9

So how come if I dont enter all last eight mandatory digits the program still display results like

(03)-6474

(03)- 63799

(02)-1 38 390

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无远思近则忧 2024-10-09 12:52:32

因为它只是在您键入时从左到右填充空格。尽管前两位数字是可选的,但它会像您使用您键入的前两个数字一样输入它们。

如果您不喜欢这种行为,您可以轻松地子类化MaskedTextBox 控件并自定义它处理键盘输入的方式。以下是几个示例控件,它们会导致数字按预期从右向左推入:

(我认为第二个例子可以更好地准确解释对基本控件所做的更改,而且它允许您在不下载示例项目的情况下查看大部分相关代码。)

Because it's simply filling in the blanks from left to right as you type. Even though the first two digits are optional, it fills them in like you've entered them with the first two numbers that you type.

If you dislike this behavior, you can easily subclass the MaskedTextBox control and customize how it handles keyboard input. Here are a couple of sample controls that cause the numbers to push in from right to left, as expected:

(I think the second example does a better job of explaining exactly what changes are being made to the base control, plus it allows you to see most of the relevant code without downloading the sample project.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文