Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

Date Must Be Between 1900 and 2100

$
0
0
Okay so basically my program is a program that validates dates in this format:
DD/MM/YYYY

However, I need I guess some sort of statement (my brain is thinking an IF ELSE) to make sure that the user does not enter a date that is less than 1900 and not greater than 2100; or in other words: it must be between 1900 and 2100.

I don't suppose anyone could help me? The code I have done so far is here:
Code:

    Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
        Dim dateString, format As String
        Dim result As Date
        Dim IsValid As Boolean = False
        dateString = txtDate.Text
        format = "dd/M/yyyy"

        If format <  Then
            IsValid = False
        End If

        Try
            result = Date.ParseExact(dateString, format, System.Globalization.CultureInfo.InvariantCulture)
            IsValid = True
        Catch
            IsValid = False
        End Try
            If (IsValid) Then
                MessageBox.Show("Valid.")
            Else
                MessageBox.Show("Invalid.")
            End If
    End Sub

The validation works but the assurance of the year doesn't work.

Thanks.

Viewing all articles
Browse latest Browse all 27514

Trending Articles