开发者

Need help with text box input

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.


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜