Use regular expressions and systems to determine the date

xiaoxiao2021-03-06  61

// Function name: Dateverify

// Parameter: Date string

// Function: Verify date input is correct, first in line with format "YYYY-MM-DD", secondary date value cannot exceed the boundary

// Return value: true --- The date value is correct, false --- Date value error

[Red] function dateverify (date) {

VAR REG = / ^ (/ d {4}) (-) (/ d {2}) / 2 (/ d {2}) $ /;

Var r = date.match (reg);

IF (r == null) Return False;

VAR D = New Date (R [1], R [3] -1, R [4]);

Var newstr = d.Getfullyear () R [2] (D.GETMONTH () 1) R [2] D.Getdate ();

Date = r [1] R [2] ((R [3] -1) 1) R [2] ((R [4] -1) 1);

Return newstr == Date;

} [/ Red]

转载请注明原文地址:https://www.9cbs.com/read-112579.html

New Post(0)