Validate Textbox input

  • Thread starter Thread starter rodger
  • Start date Start date
R

rodger

How do i validate text box entry, in VB. net

In the event that user does not make a text entry, simply pop-up a warning,

thanks

rodger
 
rodger said:
How do i validate text box entry, in VB. net
In the event that user does not make a text entry, simply pop-up a
warning,

Rodger,

It's a little tricky. You can validate text in the textbox in a couple of
events but if you want to verify that "something" was entered that can't be
done in a textbox event because theoretically your event handler has never
been called.

You also should consider what a pop-up dialog does from a UI viewpoint. If
for instance the text entry has to be 10 characters it can't very well
pop-up a message on the first 9 characters saying "it's too short."
Similarly it can't keep warning "hey it's empty" while the user is making
their way to that textbox.

You could check all the data when the user presses "Ok" but that's a little
late. Ideally the Ok button shouldn't be active until the data is actually
okay.

Tom
 
in the textbox leave event

if textbox.text = "" then
messagebox.show("Fill in the textbox","warning")
'if you want to make sure the user enters something
textbox.focus 'expect some angry users w this one ;p
end if
 
The best way to set the textbox.causevalidation property to true, then
choose the validating eventhandler.

In the event write your's validating code, and if the textbox.text not
corresponds to the condition, choose the e.cancel.

In that case the user can't leave the textbox, until writes the appropriate
value.

Search for the "Validated event" in the VS help.

Gabor
 
Back
Top