This javascript function Allow valid Date in Textbox
function validate_date(a) { var err=0; var psj=0; if (a.length != 10) { err=1 alert("Date value is not complete") return 0 } b = a.substring(3, 5)// month c = a.substring(2, 3)// '/' d = a.substring(0, 2)// day e = a.substring(5, 6)// '/' f = a.substring(6, 10)// year
if (b<1 || b>12 || isNaN(b)==true) { alert("Invalid month "+b) return 0 err = 1 }
if (isNaN(d)==true) { alert("Invalid Day "+d) return 0 err = 1 }
if (isNaN(f)==true) { alert("Invalid Year "+f) return 0 err = 1 } if (c != '/') err = 1 if (d<1 || d>31) err = 1 if (e != '/') err = 1 if (f<1935 || f>9999) err = 1
if (b==2 || b==4 || b==6 || b==9 || b==11) { if (d==31) { err=1 alert("Month "+b+" doesn't have 31 days!") return 0 } }
if (b==2) { // feb var g=parseInt(f/4) if (isNaN(g)) { err=1 } if (d>29) { err=1 alert("February " +f+ " doesn't have " +d+ " days!"); return 0; } if (d==29 && ((f/4)!=parseInt(f/4))) { err=1 alert("February " +f+ " doesn't have " +d+ " days!"); return 0; } } if (err==1) { alert("Invalid Date") return 0 } else { return 1 } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|