|
-
Apr 15th, 2005, 02:21 AM
#1
Thread Starter
New Member
How to Validate Textbox
How to validate the textbox?If empty return error message
-
Apr 15th, 2005, 02:31 AM
#2
Member
Re: How to Validate Textbox
VB Code:
If TextboxName.text = "" Then
MessageBox.Show("Please enter something")
End If
-
Apr 15th, 2005, 02:32 AM
#3
Member
Re: How to Validate Textbox
Code:
if textbox1.text="" then
msgbox("invalid")
end if
-
Apr 15th, 2005, 02:43 AM
#4
Re: How to Validate Textbox
it's a good idea to put the focus back on the textbox, and also you need those code in the Validated event of your textbox. Use the Trim function to remove empty space also (so if they enter " " it would be considered "")
VB Code:
Private Sub TextBox1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
If TextBox1.Text.Trim = "" Then
TextBox1.Focus()
MessageBox.Show("Boo!")
End If
End Sub
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Apr 15th, 2005, 04:32 AM
#5
Thread Starter
New Member
Re: How to Validate Textbox
If want to validate more than 1 text box can i include inside the sub procedure?
-
Apr 15th, 2005, 05:09 AM
#6
Fanatic Member
Re: How to Validate Textbox
VB Code:
Private Sub txt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles [u]TextBox1.Validated, TextBox2.Validated, TextBox3.Validated[/u]
Dim t As TextBox = CType(sender, TextBox)
If t.Text = "" Then
t.Focus()
MessageBox.Show("Boo!")
End If
End Sub
Just an addition to the not polite guy.
-
Apr 15th, 2005, 05:32 AM
#7
Thread Starter
New Member
Re: How to Validate Textbox
Hi,
I didn't understand this part
Dim t As TextBox = CType(sender, TextBox)
Thank You
-
Apr 15th, 2005, 05:35 AM
#8
Fanatic Member
Re: How to Validate Textbox
sender object (the one who sends a message to the event) is casted to it's TextBox form. Then pass the instance to t which of type TextBox. Then we can manipulate t, ie. display the TextBox's Name property or Tag, etc.
-
Apr 15th, 2005, 10:16 AM
#9
Thread Starter
New Member
Re: How to Validate Textbox
Hi,
Private Sub txt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated, TextBox2.Validated, TextBox3.Validated
Dim t As TextBox = CType(sender, TextBox)
If t.Text = "" Then
t.Focus()
MessageBox.Show("Boo!")
End If
End Sub
This code just validates only the first field
-
Apr 15th, 2005, 10:26 AM
#10
Thread Starter
New Member
Re: How to Validate Textbox
Hi,
Private Sub txt_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Validated, TextBox2.Validated, TextBox3.Validated
Dim t As TextBox = CType(sender, TextBox)
If t.Text = "" Then
t.Focus()
MessageBox.Show("Boo!")
End If
End Sub
This code just validates only the first field
-
Apr 15th, 2005, 11:39 AM
#11
PowerPoster
Re: How to Validate Textbox
Hi,
The it depends on what you want to validate. If you want to check each keypress for a valid number see the codebank
http://www.vbforums.com/showthread.php?t=314936
If you want to check for something other than numerics you should be able to adapt that code.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|