Hi Shrivallabha,
I think this would work.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Static REX As Object
If REX Is Nothing Then
Set REX = CreateObject("VBScript.RegExp")
With REX
.Global = False
.MultiLine = False
.Pattern = "^\d{1,2}/\d{1,2}/(\d{2}|\d{4})$"
' Change pattern to below if 2-digit year is not to be allowed.
'.Pattern = "^\d{1,2}/\d{1,2}/\d{4}$"
End With
End If
If Not TextBox1.Value = vbNullString Then
If Not REX.Test(TextBox1.Value) Then
Cancel = True
MsgBox """" & TextBox1.Value & """ is invalid." & vbCrLf & vbCrLf & _
"Please enter like mm/dd/yy, m/d/yy, or with a four-digit year.", _
vbInformation, vbNullString
TextBox1.Value = vbNullString
End If
End If
End Sub
Hope that helps,
Mark