Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Using masks to restrict data entry in Textbox

I'm using VB.NET, and using the DevExpress control suite.

I have a Textbox that should accept whole number values 5 through 10 only. I'm using the DevExpress control suite, and have reviewed the Masks information at https://documentation.devexpress.com/#WindowsForms/CustomDocument583, but can't figure out how to restrict data input using those method. I've tried the various predefined masks, and tried a few custom masks, but can't restrict to those set of digits using the Mask.

So my question is: How do I restrict user input so they can enter only 5, 6, 7, 8, 9 or 10, and no other values (including decimals), using a Mask or some other property?

DevExpress allows the use of Regular Expressions for these purposes as well, but I'm not proficient enough in RegEx to know how to write a solid expression.

I realize I could do this in code in one of the Textbox events, but I have a LOT of these, and would like to explore other options.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )
Asked:
Scott McDaniel (Microsoft Access MVP - EE MVE )
  • 2
1 Solution
 
Glen RichmondCustomer Reporting Programmer.Commented:
if you only have the values of  5, 6, 7, 8, 9 or 10 and no others, why not turn it into a selection/combo/list and save user haveing to type into a textbox at all! also removes the need of getting the mask to work!
0
 
Robert SchuttSoftware EngineerCommented:
Untested (expired trial license...), but this RegEx should do the trick:
[5-9]|10

Open in new window

which is a slightly shorter version of
5|6|7|8|9|10

Open in new window

capture of propertiesAlso, alternatives that are more suited for number ranges I think are SpinEdit or TrackBarControl which have properties for Min/Max.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareAuthor Commented:
Thanks everyone for your suggestions. Robert's suggestion answered my question directly, so I'm awarding him points.

After discussing this with the client, however, they decided to allow decimal entry for values between 5.0 and 10. I ended up with this RegEx:

([5-9]{1}(\.\d{1})?)|([1][0])

Using this, I can enter a value between 5 and 10, including decimals. So I can enter 5 or 5.3 or 8.7 or 10, but I can't enter 10.1 (which is good).
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareAuthor Commented:
Thanks again - quick and to the point!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now