Zip Code Validation

chinaboy

Member
Joined
May 12, 2007
Messages
5
Programming Experience
Beginner
Ok, I am new to vb.net and I am struggling here. I have a code that should verify that user enters five digits or produce error. The zip code must start with 450 or 550 else produce error. I think I have an idea, but i keep getting "StartsWith is not a member of Systems.Windows.Forms.TextBox"

What am I doing wrong?

PrivateSub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
' See if the text is 5 digits.
Dim zipcode AsString

If zipTextBox.Text.Length = 5 Then
zipcode = zipTextBox.Text
Else
MessageBox.Show("The Zip Code must contain 5 digits.", _
"ZIP Codes", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
EndIf
zipTextBox.Focus()

If zipTextBox.StartsWith("605") Then
shippingLabel.Text = "$25.00"
ElseIf zipTextBox.StartsWith("606") Then
shippingLabel.Text = "$30.00"
Else
MessageBox.Show("The Zip Code must beging with 605 or 606.", _
"ZIP Codes", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
EndIf
zipTextBox.Focus()
EndSub
 
Last edited:
Back
Top