JS Date validation Regular with ASP date Format function _javascript skills

Source: Internet
Author: User
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
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.