JavaScript Date Validation Regular
Copy Code code as follows:
var pattern =/^ (((1[6-9]|[ 2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d) \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((1[6-9]| [2-9]\d) (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) $/ -0?2-29-))
if (!pattern.test (Document.form1.pro_date.value)) {
Alert (the "date format is not correct, please re-enter!");
Document.form1.pro_date.focus ();
Document.form1.pro_date.select ();
return (false);
Put this code in your function and you can use it directly.
Format date in ASP
Copy Code code as follows:
<%
' ============================================
' Format time (display)
' Parameter: N_flag
' 1: "Yyyy-mm-dd hh:mm:ss"
' 2: "Yyyy-mm-dd"
' 3: "Hh:mm:ss"
' 4: "YYYY year mm month DD Day"
' 5: "YYYYMMDD"
' 6: "Yyyymmddhhmmss"
' ============================================
Function format_time (S_time, N_flag)
Dim y, M, D, H, MI, s
Format_time = ""
If IsDate (s_time) = False Then Exit Function
y = CStr (year (s_time))
m = CStr (month (s_time))
If len (m) = 1 Then m = "0" & M
D = CStr (Day (s_time))
If len (d) = 1 Then D = "0" & D
h = CStr (Hour (s_time))
If len (h) = 1 Then h = "0" & H
Mi = CStr (Minute (s_time))
If len (mi) = 1 Then mi = "0" & mi
s = CStr (second (s_time))
If len (s) = 1 Then s = "0" & S
Select Case N_flag
Case 1
' Yyyy-mm-dd Hh:mm:ss
Format_time = y & "-" & M & "-" & D & "" & H & ":" & Mi & ":" & S
Case 2
' Yyyy-mm-dd
Format_time = y & "-" & M & "-" & D
Case 3
' Hh:mm:ss
Format_time = h & ":" & Mi & ":" & S
Case 4
' YYYY year mm month DD Day
Format_time = y & "Year" & M & "Month" & D & "Day"
Case 5
' YYYYMMDD
Format_time = y & M & D
Case 6
' Yyyymmddhhmmss
Format_time= Y & M & D & H & mi & S
End Select
End Function
%>