Web input box date validity to determine a network

zhaozj2021-02-16  49

[Welfare] zosatapo

[Contact] dertyang@263.net

I use the regular expression written by the date-up page input box data to determine the function.

Contains the processing of leap years, interested in regular expressions, and needs to be dated in the webpage

Friends who are very judged can refer to it. At the same time, functions support self-date input form definitions.

1 # Auxiliary function (leap year judgment)

Function isleApyear (YEAR) {IF ((Year% 4 == 0 && Year% 100! = 0) || (Year% 400 == 0)) {Return True;}

Return false;}

2 # rating the main function

Function Datevalidation (Object, Format) {Var Regexp, Value, Index; Var Yearar, Month, Day; Var Iyear, IMONTH, IDAY; ​​VAR FMT, Regfmt, Oord; Var DateArray

IF (isobject (object)) {value = Object.value;} else if (iSString (object) &&! iSempty (object)) {value = Object;} else {return false;} if (iSempty (Format) {Return False;}

FMT = New Array ("YYYY / MM / DD", "MM / DD / YYYY", "DD / MM / YYYYYYY"); regfmt = new array ("/ ^ ([0-9] {4}) // / ([0-9] {2}) /// ([0-9] {2}) $ / "," / ^ ([0-9] {2} /// ([0-9] {2}) /// ([0-9] {4}) $ / "," / ^ ([0-9] {2}) / / / ([0-9] {2}) /// ([0-9] {4}) $ / ");

ORDFMT = New Array ("123", "312", "321");

Format = format.tolowercase (); for (index = 0; index

Iyear = parseint (ORDFMT [index] .Charat (0)); IMONTH = PARSEINT (ORDFMT [INDEX] .Charat (1)); iDay = parseint (ORDFMT [index] .Charat (2));

Break;}} if (index == fmt.length) {Alert ("Date Format Not Supported!"); Return False;

IF (regexp.test (value)) {// alert ("Date is match with format!"); DATEARRAY = value.match (regex);

Year = datearray [iyear]; month = DATEARRAY [IMONTH]; day = datearray [iDay];

// Alert ("THE date you have filled is: / nyear:" year "/ nmonth:" MONTH "/ NDAY:" day); if (Year <2001) {Alert ("Year Must Be Greater Than 2001 ! "); Returnaf (" Month <0 || Month> 12) {Alert ("Month Must Range from 1 TO 12!"); Return False;} f (day <0 || day> 31) { Alert ("Day Must Range from 1 to 31!"); Return False;} else {if (Month == 2) {IF (isleApyear && Day> 29) {Alert ("in Month 2, Day Must Range from 1 to 29! "); Return False;} f (! Isleapyear (Year) && day> 28) {Alert (" in Month 2, Day Must Range from 1 to 28! "); Return False;}}

IF ((MONTH == 4 || Month == 6 || Month == 9 || Month == 11) && ("in this month, day must range from 1 to 30!" Return False;}}

} Else {alert ("Date isn't matched with format! / Ndate format: format); return false;}

Return True;}

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

New Post(0)