Validating form fields in VB.NET
-
I have a form in a software program where the user can type in their information. When the zip cod form field is empty and I submit the form I get an error that says the string is in the wrong format, but when the field is filled in I don't get the error. How do I check to see if someone has filled in a text box in the form or if it is empty?
-
I have a form in a software program where the user can type in their information. When the zip cod form field is empty and I submit the form I get an error that says the string is in the wrong format, but when the field is filled in I don't get the error. How do I check to see if someone has filled in a text box in the form or if it is empty?
try this: Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then MsgBox("You Must put something in here first") Exit Sub End If continue on with your program stuff here........ End Sub
-
I have a form in a software program where the user can type in their information. When the zip cod form field is empty and I submit the form I get an error that says the string is in the wrong format, but when the field is filled in I don't get the error. How do I check to see if someone has filled in a text box in the form or if it is empty?
You might have Google it before you post it. Anyway here's something that you can use for your purpose.
' Validate a US ZIP code
' Example:
' MessageBox.Show(IsValidUsZip("12345")) ' => True
' MessageBox.Show(IsValidUsZip("12345-1234")) ' => True
' MessageBox.Show(IsValidUsZip("12345-12345")) ' => FalseFunction IsValidUsZip(ByVal zip As String) As Boolean
Return System.Text.RegularExpressions.Regex.IsMatch(zip, _
"^(\d{5}-\d{4})|(\d{5})$")
End Function- Stop thinking in terms of limitations and start thinking in terms of possibilities -