JS date verification regular appendix asp date Formatting Function

Source: Internet
Author: User

Javascript date validation regular Copy codeThe Code is as follows: var pattern =/^ (1 [6-9] | [2-9] \ d) \ d {2})-(0? [1, 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 incorrect. Please enter it again! ");
Document. form1.pro _ date. focus ();
Document. form1.pro _ date. select ();
Return (false );

Put this code into your Function and you can use it directly.

Format a date in ASPCopy codeThe Code is as follows: <%
'================================================ =====
'Formatting time (displayed)
'Parameter: n_Flag
'1: "yyyy-mm-dd hh: mm: ss"
'2: "yyyy-mm-dd"
'3: "hh: mm: ss"
'4: "mm dd, yyyy"
'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-mm-dd
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.