Home > Web Front-end > JS Tutorial > JS date verification regular with asp date formatting function_javascript skills

JS date verification regular with asp date formatting function_javascript skills

WBOY
Release: 2016-05-16 18:46:48
Original
1012 people have browsed it

javascript date validation regular expression

Copy code The code is 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]|1d|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 re-enter!");
document.form1.pro_date.focus();
document.form1.pro_date.select();
return( false);

Put this code into your Function and use it directly

Format date in ASP
Copy code The code is 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日"
' 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 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
%>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template