Imports System.Text.RegularExpressions
Public Class ReservationsForm
Inherits System.Windows.Forms.Form
Private Shared anInstance As ReservationsForm
Dim checkinDate As Date
Dim checkoutdate As Date
Dim phoneString As String
Dim stateString As String
Dim zipString As String
Dim cardString As String
Private Sub lnameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles lnameTextBox.Validating
'Validate the Last Name textbox.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure Last Name is not blank, and is not Numeric.
If Not Regex.IsMatch(lnameTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
ErrorProvider1.SetError(lnameTextBox, "Please enter a Last Name. Last Name can not contain numbers.")
lnameTextBox.SelectAll()
lnameTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(lnameTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub fnameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles fnameTextBox.Validating
'Validate the First Name textbox.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure First Name is not blank, and is not Numeric.
If Not Regex.IsMatch(fnameTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
ErrorProvider1.SetError(fnameTextBox, "Please enter a first Name. First Name can not contain numbers.")
fnameTextBox.SelectAll()
fnameTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(fnameTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub addressTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles addressTextBox.Validating
'Validate the address textbox.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure address is not blank.
If addressTextBox.Text = "" Then
ErrorProvider1.SetError(addressTextBox, "Please enter an address.")
addressTextBox.SelectAll()
addressTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(addressTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub cityTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cityTextBox.Validating
'Validate the City textbox.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure City is not blank, and is not Numeric.
If Not Regex.IsMatch(cityTextBox.Text, "^[a-zA-Z'`-´\s]{1,40}$") Then
ErrorProvider1.SetError(cityTextBox, "Please enter a City. City can not contain numbers.")
cityTextBox.SelectAll()
cityTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(cityTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub stateTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles stateTextBox.Validating
'Validate the State textbox.
'Ensure the State is upper case.
stateString = stateTextBox.Text.ToUpper
stateTextBox.Text = stateString
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure State is not blank, and is not Numeric.
If Len(stateString) <> 2 OrElse Not Regex.IsMatch(stateString, "^[A-Z]{1,40}$") Then
ErrorProvider1.SetError(stateTextBox, "Please enter a State. State can not contain numbers.")
stateTextBox.SelectAll()
stateTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(stateTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub phoneTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles phoneTextBox.Validating
'Validate the Phone textbox.
'Mask set to numeric, no need to check for alpha characters.
phoneString = phoneTextBox.Text
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure Phone number is not blank, and contains all 10 digits.
If Len(phoneString) < 13 Then
ErrorProvider1.SetError(phoneTextBox, "Phone number must contain 10 digits.")
phoneTextBox.SelectAll()
phoneTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(phoneTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub zipTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles zipTextBox.Validating
'Validate the zip code.
'Mask set to numeric, no need to check for alpha characters.
zipString = zipTextBox.Text
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
'Ensure Zip Code is numeric and contains all 5 digits.
If Not IsNumeric(zipTextBox.Text) OrElse Not Len(zipString) = 5 Then
ErrorProvider1.SetError(zipTextBox, "Zip Code must contain 5 digits.")
zipTextBox.SelectAll()
zipTextBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(zipTextBox, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub checkInDateTimePicker_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles checkInDateTimePicker.Validating
'Validate the check in date.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
checkinDate = .checkInDateTimePicker.Value
If checkinDate < Date.Now.Date Then
ErrorProvider1.SetError(checkInDateTimePicker, "Check in date can not be less than todays date.")
.checkInDateTimePicker.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(checkInDateTimePicker, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub checkOutDateTimePicker_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles checkOutDateTimePicker.Validating
'Validate the check out date.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
checkoutdate = .checkOutDateTimePicker.Value
If Not checkoutdate > checkinDate Then
ErrorProvider1.SetError(checkOutDateTimePicker, "Check out date must be greater than check in date.")
.checkOutDateTimePicker.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(checkOutDateTimePicker, Nothing)
.Clear()
End With
End If
End With
End Sub
Private Sub cardTypeComboBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cardTypeComboBox.Validating
'Validate Card Type.
With Me
'Clear the errorprovider.
ErrorProvider1.Clear()
If .cardTypeComboBox.SelectedIndex = -1 Then
ErrorProvider1.SetError(cardTypeComboBox, "Please select a Card Type.")
.cardTypeComboBox.Focus()
Else
'Ensure the error is Nothing and Clear the error provider.
With ErrorProvider1
.SetError(cardTypeComboBox, Nothing)
.Clear()
End With
End If
End With
End Sub
End Sub