Link to home
Start Free TrialLog in
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )Flag for United States of America

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.
Avatar of Glen Richmond
Glen Richmond
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott McDaniel (EE MVE )

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).
Thanks again - quick and to the point!