Home
Manage Your Code
Snippet: Date Regular Expressions (VB.NET)
Title: Date Regular Expressions Language: VB.NET
Description: Validating a date Views: 108
Author: Tom Baggett Date Added: 7/1/2009
Copy Code  
1Imports System.Text.RegularExpressions
2
3
4    Private Sub txtJobDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJobDate.Leave
5        Try
6            Dim re As String = "^\d{1,2}\/\d{1,2}\/\d{4}$"
7            Dim coDate As String = txtJobDate.Text.Trim()
8
9            If Not Regex.IsMatch(coDate, re) Then
10                MsgBox("NO THAT IS NOT A VALID DATE!!! - use MM/DD/YYYY", MsgBoxStyle.Critical)
11                txtJobDate.Text = ""
12                txtJobDate.Focus()
13                Exit Sub
14            End If
15        Catch ex As Exception
16            MsgBox("OOps: " & vbCrLf & ex.Message)
17        End Try
18    End Sub