Introduction
This article explains simple ways to validate user input in a text box.
Here is the code; let's say we have two textboxes named txt1 and txt2 and two
buttons btn1 and btn2. Add the code given below:
Collapse
Private Sub btn1_Click(ByVal sender As [Link], _
ByVal e As [Link]) Handles [Link]
If ([Link] = "") Then
MsgBox("Blank not Allowed", [Link], "Verify")
Else
MsgBox([Link], [Link], "Verify")
End If
[Link]()
[Link]()
End Sub
Private Sub txt1_KeyPress(ByVal sender As Object, _
ByVal e As [Link]) _
Handles [Link]
If ([Link]([Link]) = False) Then
If ([Link]([Link])) Or ([Link]([Link])) Then
'do nothing
Else
[Link] = True
MsgBox("Sorry Only Character & Spaces Allowed!!", _
[Link], "Verify")
[Link]()
End If
End If
End Sub
Private Sub txt2_KeyPress(ByVal sender As Object, _
ByVal e As [Link]) _
Handles [Link]
If ([Link]([Link]) = False) Then
If ([Link]([Link])) Then
'do nothing
Else
[Link] = True
MsgBox("Sorry Only Digits Allowed!!", _
[Link], "Verify")
[Link]()
End If
End If
End Sub
Private Sub btn2_Click(ByVal sender As [Link], _
ByVal e As [Link]) Handles [Link]
If ([Link] = "") Then
MsgBox("Blank not Allowedt", [Link], "Verify")
Else
MsgBox([Link], [Link], "Verify")
End If
[Link]()
[Link]()
End Sub