防止 MaskedTextbox 中出现空格

发布于 2024-10-07 01:50:39 字数 92 浏览 0 评论 0原文

如何防止屏蔽文本框中出现空格?使用了 KeyPress 但 e.handled 不起作用。有人可以指导我查看一篇显示如何处理此问题的帖子吗?屏蔽文本框用于 ssn。 谢谢

How can I prevent spaces in a maskedtextbox? Used KeyPress but the e.handled doesnt work. Can somebody direct me to a post that shows how to handle this? The masked textbox is used for ssn.
Thanks

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

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

发布评论

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

评论(2

风启觞 2024-10-14 01:50:39

您需要的不是 9,而是 0,因为 9 允许空格作为可接受的字符

美国社会安全号码掩码如下所示:

myMaskedTextBox.Mask = "000-00-0000";

此外,您需要确保将 ResetOnSpace 属性设置为

Rather than 9's you'd want 0's, due to 9's allowing spaces as acceptable characters

A US Social Security Number mask would look like this:

myMaskedTextBox.Mask = "000-00-0000";

In addition you'll want to make sure the ResetOnSpace property is set to false.

多情癖 2024-10-14 01:50:39

您可以设置 MaskedTextBox.Mask< /code> 属性将输入限制为您想要的字符。

这应该适用于社会安全号码:

myMaskedTextBox.Mask = "000-00-0000";

编辑:已修复,9 接受数字或空格,而 0 仅接受数字。

You can set the MaskedTextBox.Mask property to limit the input to just the characters that you want.

This should work for Social Security Numbers:

myMaskedTextBox.Mask = "000-00-0000";

EDIT: Fixed, 9 accepts a digit or a space while 0 only accepts digits.

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