|
Valid date format
This example uses regular expressions to check
whether a date is in the format of 2001-10-06 . It does not
check for wrong months entered like 14 or incorrect years ,
it just checks the format . This format is used imn many countries
but if you are in the UK the more common format is 10-12-2001
where 10 is the day , month is 12 and so on.
Code :
<%
Function ValidFormat(dteDate)
'new object variable
Dim objRegExp
'declare a new instance of RegExp object
Set objRegExp = New RegExp
'our pattern to match
objRegExp.Pattern = "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
'test the date
blnValid = objRegExp.Test(dteDate)
'display a message depending on whether it is true or false
If blnValid Then
Response.Write "Correctly formatted date<br>"
Else
Response.Write "Incorrectly formatted date<br>"
End If
Set objRegExp = Nothing
End Function
%>
<% ValidFormat("2000-10-06") %>
<% ValidFormat("2000-111-04") %>
<% ValidFormat("06-06-2001") %>
|