Date validation Javascript

Source: Internet
Author: User
Date VerificationFunction isdate (STR) {var strseparator = "-"; // Date delimiter var strdatearray; var intyear; var intmonth; var intday; var boolleapyear; var strdate; strdate = STR; strdatearray = strdate. split (strseparator); // extract the IF (strdatearray. length! = 3) {alert ("the date you entered is incorrect"); Return "false";} intyear = parseint (strdatearray [0], 10 ); intmonth = parseint (strdatearray [1], 10); intday = parseint (strdatearray [2], 10); If (isnan (intyear) | isnan (intmonth) | isnan (intday) {alert ("your input date error"); Return "false";} If (intmonth> 12 | intmonth <1) {alert ("date error, the month must be a number between 0 and 12"); Return "false ";} if (intmonth = 1 | intmonth = 3 | intmonth = 5 | intmonth = 7 | intmonth = 8 | intm Onth = 10 | intmonth = 12) & (intday> 31 | intday <1) {alert ("date error, the day of the month you entered must be between 1-31 "); Return" false ";} if (intmonth = 4 | intmonth = 6 | intmonth = 9 | intmonth = 11) & (intday> 30 | intday <1 )) {alert ("date error, the day of the month you entered must be between 1-30"); Return "false" ;}if (intmonth = 2) {If (intday <1) {alert ("date error, month cannot be zero or null"); Return "false" ;}boolleapyear = false; if (intyear % 400 = 0) | (intyear % 4 = 0 & intyear % 100! = 0) // determine the leap year boolleapyear = true; else boolleapyear = false; // If (boolleapyear) {If (intday> 29) {alert ("date error, the day of March February of a leap year must be between 1 and 29 "); Return" false ";}} else {If (intday> 28) {alert (" date error, the date of March must be between 1 and 28 "); Return" false ";}}return" true ";} Date comparisonVaR rukua, rukub, rukuc, SCA, SCB, SCC, fir, SEC; FIR = document. form1.produce _ date. value. split ("-"); sec = document. form1.stock _ in_date.value.split ("-"); rukua = parseint (SEC [0]); rukub = parseint (SEC [1]); rukuc = parseint (SEC [2]); SCA = parseint (FIR [0]); SCB = parseint (FIR [1]); SCC = parseint (FIR [2]); If (SCA> rukua) {alert ("warehouse receiving date cannot be earlier than the production date"); document. form1.stock _ in_date.focus (); Return false;} If (SCA = rukua & SCB> rukub) {alert ("the database date cannot be earlier than the production date"); document. form1.stock _ in_date.focus (); Return false;} If (SCA = rukua & SCB = rukub & SCC> rukuc) {alert ("warehouse receiving date cannot be earlier than the production date"); document. form1.stock _ in_date.focus (); Return false ;}

 

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.