Public Shared Function IsDate(ByVal strChkParam As String) As Boolean
If strChkParam.Length = 0 Then Return True
Dim regex As Regex
If Not IsHalfEisuuji(strChkParam) Then
Return False
End If
Dim InputFormat1 As String = "YYYYMMDD"
Dim InputFormat2 As String = "YYYYMM"
Dim InputFormat3 As String = "MMDD"
Dim InputFormat4 As String = "YYYY/MM/DD"
Dim InputFormat5 As String = "YYYY/MM"
Dim InputFormat6 As String = "MM/DD"
Select Case strChkParam.Length
Case InputFormat4.Length
regex = New System.Text.RegularExpressions.Regex("^\d{4}/\d{2}/\d{2}$")
Case InputFormat5.Length
regex = New System.Text.RegularExpressions.Regex("^\d{4}/\d{2}$")
Case InputFormat6.Length
regex = New System.Text.RegularExpressions.Regex("^\d{2}/\d{2}$")
End Select
If Not (regex Is Nothing) Then
If (Not (regex.IsMatch(strChkParam))) Then
Return False
End If
End If
strChkParam = strChkParam.Replace("/", "")
If IsNumber(strChkParam) Then
Select Case strChkParam.Length
Case InputFormat3.Length
Try
Convert.ToDateTime(DateTime.Now.Year.ToString() + "/" + strChkParam.Substring(0, 2) + "/" + strChkParam.Substring(2, 2))
Catch ex As Exception
Return False
End Try
Case InputFormat2.Length
Try
Convert.ToDateTime(strChkParam.Substring(0, 4) + "/" + strChkParam.Substring(4, 2) + "/01")
Catch ex As Exception
Return False
End Try
Case InputFormat1.Length
Try
Convert.ToDateTime(strChkParam.Substring(0, 4) + "/" + strChkParam.Substring(4, 2) + "/" + strChkParam.Substring(6, 2))
Catch ex As Exception
Return False
End Try
Case Else
Return False
End Select
Else
Return False
End If
Public Shared Function IsNumber(ByVal strChkParam As String) As Boolean
If strChkParam.Length = 0 Then Return True
Dim regex As Regex
If IsHalfEisuuji(strChkParam) Then
regex = New System.Text.RegularExpressions.Regex("^\d*$")
If regex.IsMatch(strChkParam) And IsHalfEisuuji(strChkParam) Then
Return True
End If
End If