The front desk in jquery about date correctness check

Source: Internet
Author: User

A recent project summary has a date control in which the use of a date control in a previous project typically has the following conditions.

(1) When you click on the text box to pop up the Calendar control's selection screen, manually select the time on the calendar control. This practice has a great advantage is not to do the date of the correctness of the check, the general situation is only to compare from and to the relationship between the date order to ensure the correctness. This project is also most commonly used.

(2) Click the calendar symbol to pop up the calendar selection screen, text box content can be entered manually. In this case, there are usually two kinds of check, one is the text box after the content input, the way to go JS, by invoking the validity of the date, the error message or continue the next operation. The other is for the input of the text box, limit the input, through the KeyUp listening input content, and then return the desired content to make some character input invalid.

(3) For the text box input problem, usually through the input method of the system to control only the English characters and the number of the system, you need to do the corresponding code in the background, because IE text box is very silly, even if you limit the input, for the universal copy and paste text box can not be refused.

The other one is not related to this check, that is, the invalid text box settings, invalid text content is not to be taken. In general, the method of hiding variables is used to solve the problem.

The code for date validation references the following code:

1 function Isvalidatedate (date) {2Date =$.trim (date);3      varReg =/^ (\d{4})-(\d{2})-(\d{2})$/;4 reg.exec (date);5      if(!reg.test (date) && regexp.$2<= A&& regexp.$3<= to) {6          return false;7      }8      varYear , month, day;9Year = parseint (Date.split ("-")[0],Ten);Tenmonth = parseint (Date.split ("-")[1],Ten); OneDay = parseint (Date.split ("-")[2],Ten); A      if(! ((1<= month) && ( A>= month) && ( to>= Day) && (1<=Day)))  { -          return false; -      } the      if(Month <=7) && ((Month%2) ==0) && (Day >= to)) { -          return false; -      } -      if(Month >=8) && ((Month%2) ==1) && (Day >= to)) { +          return false; -      } +      if(Month = =2) { A          if(Year% -==0) || (Year%4==0) && (Year% -!=0))) { at              if(Day > in) { -                  return false; -              } -}Else { -              if(Day > -) { -                  return false; in              } -          } to      } +      return true; -}
View Code

The front desk in jquery about date correctness check

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.