需要文本框输入帮助

发布于 2024-10-13 06:36:32 字数 260 浏览 7 评论 0原文

它实际上是一个网格列,但它的功能就像一个文本框。我需要它只能接受数字,但它必须能够接受带有前导 0 的数字。我会用什么作为面膜来获得这个结果?如果我使用任何类型的数字掩码,那么它将截掉前导 0,例如 002456841。如果我不使用数字掩码,则将接受字符,这是不可接受的。

难道我跳出框框思考的还不够吗?我也在想,也许不是使用循环或其他东西来确保它只是数字,而是删除/弹出一条消息(如果不是),而不是使用掩码......但我只是不知道,我宁愿只拥有盒子,所以它只接受数字,但可以是任何数字。

It's actually a grid column but it functions just like a textbox. I need it to be able to accept numbers only, but it has to be able to accept numbers with leading 0's. What would I use as a mask to get this result? If I do any kind of numeric mask then it will cut off the leading 0's, eg 002456841. If I don't use a numeric mask, then characters will be accepted which is unacceptable.

Am I not thinking outside of the box enough with this? I was also thinking like maybe instead of a mask using a loop or something to make sure it's only numbers and erase/pop up a message if it's not...but I just don't know, I would rather just have the box so it only accepts numbers but any number.

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

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

发布评论

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

评论(4

演多会厌 2024-10-20 06:36:32

只需阅读每个按键并拒绝任何超出您范围的按键。实现取决于这是一个 Web 网格还是一个 windows/wpf 网格。

Just read each key press and reject any that fall outside of your range. Implementation depends on if this is a web grid or a windows/wpf grid.

横笛休吹塞上声 2024-10-20 06:36:32

好吧,这里有几个选择:

  • 首先,使用正则表达式来验证
  • 其次,使用 jQuery 的 Masked 输入插件。

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

更新文本
嗯,我不知道为什么你必须使用 Java,我只是建议你尝试使用带有正则表达式的 jQuery 插件来屏蔽。我认为这应该可以解决你的问题...如果你对你的正则表达式有疑问,那么你可以随时测试它
http://www.regextester.com/

希望这会有所帮助。

Well, you have couple options here:

  • First, use a regular expression to validate
  • Second, use a jQuery's Masked input plugin.

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

Updated Text
hmm, I am not sure why will you have to use Java, I was just suggesting you to try use the jQuery plugin with a regular expression to mask with. I think that should solve your issue... also if you have doubts on your regex then you can always test it through
http://www.regextester.com/

Hope this helps.

戈亓 2024-10-20 06:36:32

如果您使用的是 asp.net webforms(您没有说明哪个平台/语言),那么您可以使用 MS Ajax FilteredTextBox 扩展程序,它可以让您指定可以输入的内容。它连接到一个 asp.net TextBox,当按下不允许的字符键时,不会发生任何事情。

如果您想要具体答案,我建议您在问题中提供更多信息。特别是您使用的平台/语言。C# 相当广泛,并且在您的问题或标题中没有提及,只是作为标签。

If you're working in asp.net webforms (you didn't say which platform/language), then you can use the MS Ajax filteredTextBox extender, which lets you specify what can be entered. It connects to an asp.net TextBox and when a not allowed character key is pressed, nothing happens.

I'd suggest a bit more information in your questions if you want specific answers. Especially what platform/language your working in. C# is rather broad, and isn't mentioned in your question or title, just as a tag.

阳光的暖冬 2024-10-20 06:36:32

我发现,我使用的是正则表达式 '\d{1,10}' 但它仍然不起作用,我在 setter 和 getter 中将数据类型设置为 int ,但它不起作用,所以我将其设置为字符串,然后当我需要以这种方式使用它时将其解析/转换为 int 。

I figured it out, I was using a RegEx '\d{1,10}' but it was still not working, I had the data type in the setters and getters as an int which wasn't working, so I set it as string and then parsed/cast it as an int when I needed to use it that way which worked.

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