Solved

Using masks to restrict data entry in Textbox

Posted on 2014-11-04
4
311 Views
Last Modified: 2014-11-18
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
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:Glen Richmond
ID: 40421382
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
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40421418
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
 
LVL 85
ID: 40450718
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
 
LVL 85
ID: 40450721
Thanks again - quick and to the point!
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question