happypete Posted October 13, 2012 Share Posted October 13, 2012 Hi, I'm a complete novice with Javascript. I have a script that validates a date and I'm trying to change the date format from: dd/mm/yyyy to: mm/dd/yyyy function validDate(input) { input = input.split('/'); if(input.length != 3)return false; for(var counter = 0;counter < 3;counter++) if(input[counter] == '' || isNaN(input[counter]) || input[counter] < 1)return false; else input[counter] = input[counter] * 1; var compare = new Date(input[2], input[1] - 1, input[0]); if(compare.getFullYear() != input[2])return false; if(compare.getMonth() != input[1] - 1)return false; if(compare.getDate() != input[0])return false; return compare; } Link to comment https://forums.phpfreaks.com/topic/269432-date-validation/ Share on other sites More sharing options...
happypete Posted October 13, 2012 Author Share Posted October 13, 2012 solved function validDate(input) { input = input.split('/'); if(input.length != 3)return false; for(var counter = 0;counter < 3;counter++) if(input[counter] == '' || isNaN(input[counter]) || input[counter] < 1)return false; else input[counter] = input[counter] * 1; var compare = new Date(input[2], input[0] - 1, input[1]); if(compare.getFullYear() != input[2])return false; if(compare.getMonth() != input[0] - 1)return false; if(compare.getDate() != input[1])return false; return compare; } Link to comment https://forums.phpfreaks.com/topic/269432-date-validation/#findComment-1385019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.