Scott McDaniel (EE MVE )
asked on
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.
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.
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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).
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][
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).
ASKER
Thanks again - quick and to the point!