1var date_regex = /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/;
2if (!(date_regex.test(testDate))) {
3 return false;
4}
1function validatedate(inputText,DateFormat)
2{
3// format dd/mm/yyyy or in any order of (dd or mm or yyyy) you can write dd or mm or yyyy in first or second or third position ... or can be slash"/" or dot"." or dash"-" in the dates formats
4var invalid = "";
5var dt = "";
6var mn = "";
7var yr = "";
8var k;
9var delm = DateFormat.includes("/") ? "/" : ( DateFormat.includes("-") ? "-" : ( DateFormat.includes(".") ? "." : "" ) ) ;
10var f1 = inputText.split(delm);
11var f2 = DateFormat.split(delm);
12for(k=0;k<=2;k++)
13{
14 dt = dt + (f2[parseInt(k)]=="dd" ? f1[parseInt(k)] : "");
15 mn = mn + (f2[parseInt(k)]=="mm" ? f1[parseInt(k)] : "");
16 yr = yr + (f2[parseInt(k)]=="yyyy" ? f1[parseInt(k)] : "");
17}
18var mn_days = "0-31-" + (yr % 4 == 0 ? 29 : 28) + "-31-30-31-30-31-31-30-31-30-31";
19var days = mn_days.split("-");
20if( f1.length!=3 || mn.length>2 || dt.length>2 || yr.length!=4 || !(parseInt(mn)>=1 && parseInt(mn)<=12) || !(parseInt(yr)>=parseInt(1900) && parseInt(yr)<=parseInt(2100)) || !(parseInt(dt)>=1 && parseInt(dt)<=parseInt(days[parseInt(mn)])) )
21{
22 invalid = "true";
23}
24alert( ( invalid=="true" ? "Invalid Date" : "Valid Date") );
25}