Advertisement
Guest User

Untitled

a guest
May 28th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function isValidDate(){
  3.     var date = parseFloat(document.getElementById('date').value);
  4.     check = /^([0-9]){2})-([0-9]{2})-([0-9]{4})$/;
  5.  
  6.     if(!date.match(check)){
  7.         alert("Error:Date format wrong: ##-##-####");
  8.         return false;
  9.     }else{
  10.         //it only will works if the  date will be exacly 00-00-0000  /  00/00/0000
  11.         // get all the caracters bettween one string index's link below
  12.         //https://www.w3schools.com/jsref/jsref_substr.asp
  13.  
  14.         var dateDay = parseInt(date.substr(0,2));
  15.         var dateMonth = parseInt(date.substr(2,4));
  16.         var dateYear = parseInt(date.substr(5,9));
  17.         // This year that will be registred is a leap year ?
  18.         var leapYear = false; // Starts with false  but needs to have comparison
  19.         if( (dateYear % 400 == 0) || (dateYear % 4 == 0   && dateYear % 100 == 0) )
  20.         {
  21.             leapYear = true;
  22.         }else{
  23.             leapYear = false;
  24.         }
  25.  
  26.         var daysInMonth;
  27.         //4,6,9,11  daysInMonth = 30 if the month is April, June, September, or November
  28.         if(dateMonth == 4 || dateMonth == 6 || dateMonth == 9|| dateMonth == 11)
  29.         {
  30.             daysInMonth = 30;
  31.         }// ... others if for all months
  32.         //  needs to make others decision and make  the data format verification  
  33.         //in date.match(check())... improved
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement