Link to home
Start Free TrialLog in
Avatar of running32
running32

asked on

Validate Masked Input Text Box

How do I validate to see if a value has been entered into a masked input box.

Thanks

   If txtDOB.CtlText = "" Then
            MsgBox("Please enter DOB")
            txtDOB.Focus()
            Exit Sub
        End If
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

for dates, you should really use a DateTimePicker control.

For other mask, see http://www.codeproject.com/vb/net/cpflexmaskeditbox.asp
Regular expression validation.

Bob
Avatar of running32
running32

ASKER

Thanks guys
Sorry I hit enter too quickly.

Regular validation does not work.  Even when I enter a value I get the msgbox.

 If txtDOB.Text = "" Then
            MsgBox("Please enter DOB")
            txtDOB.Focus()
            Exit Sub
        End If

and I would rather not use a datetime picker control.  Thanks for the input
what about the mask edit control ?
I wanted to validate that there is actually a value in the text box before I proceed.  My problem is that because it is masked I'm not sure how to test.
I tried this below and I can see the string as 08/17/1975 but it does not reconize there are # there

 Dim instrdob As Integer
        instrdob = InStr(1, txtDOB.CtlText, "[0-9]", CompareMethod.Text)
        If instrdob = 0 Then
            MsgBox("Please enter DOB")
            txtDOB.Focus()
            Exit Sub
        End If
You are already using a masked edit control! Which one is it?

I suppose that the CtlText property you are using gives you the prompts characters (/-_ ...). You must have another property that exclude them (this property is different from each control). Add you control to the Watch window while it as no value in it and check to see which property as the raw value in it.
I'm new to vb.net.  I'm using the Masked EditControl Version 6.0 if that helps any.  In the mask session I put ##/##/####.

I'm not sure how to add the control to the Watch window.  But if I display a message box I get back __/___/____ and the value count is always 10.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada 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
ClipText it is. Thank you.