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
Solved

Using masks to restrict data entry in Textbox

Posted on 2014-11-04
4
299 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
  • 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 84
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 84
ID: 40450721
Thanks again - quick and to the point!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

839 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