Link to home
Start Free TrialLog in
Avatar of wally_davis
wally_davisFlag for United States of America

asked on

validating something was inputted into a maskedTextBox

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

ASKER CERTIFIED SOLUTION
Avatar of SaedSalman
SaedSalman
Flag of Jordan 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 wally_davis

ASKER

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

Figured out another solution. Please delete question.
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. :)