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}
1
2function validatedate(inputText,DateFormat)
3{
4// 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
5var invalid = "";
6var dt = "";
7var mn = "";
8var yr = "";
9var k;
10var delm = DateFormat.includes("/") ? "/" : ( DateFormat.includes("-") ? "-" : ( DateFormat.includes(".") ? "." : "" ) ) ;
11var f1 = inputText.split(delm);
12var f2 = DateFormat.split(delm);
13for(k=0;k<=2;k++)
14{
15 dt = dt + (f2[parseInt(k)]=="dd" ? f1[parseInt(k)] : "");
16 mn = mn + (f2[parseInt(k)]=="mm" ? f1[parseInt(k)] : "");
17 yr = yr + (f2[parseInt(k)]=="yyyy" ? f1[parseInt(k)] : "");
18}
19var mn_days = "0-31-" + (yr % 4 == 0 ? 29 : 28) + "-31-30-31-30-31-31-30-31-30-31";
20var days = mn_days.split("-");
21if( 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)])) )
22{
23 invalid = "true";
24}
25alert( ( invalid=="true" ? "Invalid Date" : "Valid Date") );
26}
27
28