需要文本框输入帮助
它实际上是一个网格列,但它的功能就像一个文本框。我需要它只能接受数字,但它必须能够接受带有前导 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需阅读每个按键并拒绝任何超出您范围的按键。实现取决于这是一个 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.
好吧,这里有几个选择:
http://digitalbush.com/projects/masked-input-plugin/#demo
更新文本
嗯,我不知道为什么你必须使用 Java,我只是建议你尝试使用带有正则表达式的 jQuery 插件来屏蔽。我认为这应该可以解决你的问题...如果你对你的正则表达式有疑问,那么你可以随时测试它
http://www.regextester.com/
希望这会有所帮助。
Well, you have couple options here:
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.
如果您使用的是 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.
我发现,我使用的是正则表达式 '\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.