Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isValidDate(){
- var date = parseFloat(document.getElementById('date').value);
- check = /^([0-9]){2})-([0-9]{2})-([0-9]{4})$/;
- if(!date.match(check)){
- alert("Error:Date format wrong: ##-##-####");
- return false;
- }else{
- //it only will works if the date will be exacly 00-00-0000 / 00/00/0000
- // get all the caracters bettween one string index's link below
- //https://www.w3schools.com/jsref/jsref_substr.asp
- var dateDay = parseInt(date.substr(0,2));
- var dateMonth = parseInt(date.substr(2,4));
- var dateYear = parseInt(date.substr(5,9));
- // This year that will be registred is a leap year ?
- var leapYear = false; // Starts with false but needs to have comparison
- if( (dateYear % 400 == 0) || (dateYear % 4 == 0 && dateYear % 100 == 0) )
- {
- leapYear = true;
- }else{
- leapYear = false;
- }
- var daysInMonth;
- //4,6,9,11 daysInMonth = 30 if the month is April, June, September, or November
- if(dateMonth == 4 || dateMonth == 6 || dateMonth == 9|| dateMonth == 11)
- {
- daysInMonth = 30;
- }// ... others if for all months
- // needs to make others decision and make the data format verification
- //in date.match(check())... improved
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement