Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

validating something was inputted into a maskedTextBox

Posted on 2009-04-11
4
Medium Priority
?
997 Views
Last Modified: 2013-12-17
I'm using a maskedTextBox with the following masks
- maskedTextBoxAccountName = LLLLLLLLLLLLLLLL
- maskedTextBoxAccountNumber = 00000

How do I validate the user has entered something? If I use Validated or Validating Events, (see code below) they get in the way if I want to say "Exit" the program by clicking on the Exit button or if I click on the "Clear Form" button Events. I've been at this one for a while and could sure use the help!
Thanks Experts!
Wally
private void maskedTextBoxAcctNameInput_Validated(object sender, EventArgs e)
        {
            if (maskedTextBoxAcctNameInput.Text == string.Empty)
            {
                MessageBox.Show("You must enter an Account Name");
                maskedTextBoxAcctNameInput.Focus();
            }
        }
 
        private void maskedTextBoxAcctNumberInput_Validated(object sender, EventArgs e)
        {
            if (maskedTextBoxAcctNumberInput.Text == string.Empty)
            {
                MessageBox.Show("You must enter an Account Number");
                maskedTextBoxAcctNumberInput.Focus();
            }
        }

Open in new window

0
Comment
Question by:wally_davis
[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
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
SaedSalman earned 1500 total points
ID: 24125762
I am not sure that I got your question right :)
> How do I validate the user has entered something?
User should press something to get in, Such as Login's button or press Enter ..etc, Right ? if Yes, you can handle that event and validate user's input.

0
 

Author Comment

by:wally_davis
ID: 24126504
Sorry, I should have explained just a little more in depth.
Lets say that we have two maskedTextBox controls on a Winddows Form.
One mTB only allows text. The other only numbers.
Lets just say I skip one of those mTB's and don't enter any data in. What I'm trying to do is make
sure that something is entered, but, at the same time, not intefering with a control like and Exit (if I want to exit the application suddenly) button or a Clear Form button, if I want to reset the form on a whims notice. The problem I'm having is that when I use "Validating" Event Handler.
I'm atttempting to use the Validate Event handler in a Function in hopes that I can handle any one "Validating" event, like the Exit or Clear Form button. Below is some code I have that I somehow need to put into a Function along with the Exit button and Clearm Form buttons to handle those two events.
private void maskedTextBoxAcctNameInput_Validated(object sender, EventArgs e)
        {
            if (maskedTextBoxAcctNameInput.Text == string.Empty)
            {
                MessageBox.Show("You must enter an Account Name");
                maskedTextBoxAcctNameInput.Focus();
            }
        }
 
        private void maskedTextBoxAcctNumberInput_Validated(object sender, EventArgs e)
        {
            if (maskedTextBoxAcctNumberInput.Text == string.Empty)
            {
                MessageBox.Show("You must enter an Account Number");
                maskedTextBoxAcctNumberInput.Focus();
            }
        }

Open in new window

0
 

Author Comment

by:wally_davis
ID: 24163074
Figured out another solution. Please delete question.
0
 

Author Closing Comment

by:wally_davis
ID: 31569256
Although it did'nt completely give me the answer I needed, you helped me rethink where the actual check placements within the code needed to go. Thank you very much for your time. :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 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