Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
JavaScript - CheckDate()
//CheckDate(input) //V8 3.31.1 print("START"); var myVar = "9/7/2015"; if (CheckDate(myVar)) print("true"); else print("false"); print("END"); function CheckDate(input) { //var validformat=/^\d{2}\/\d{2}\/\d{4}$/; //Basic check for format validity var returnval=false; try { if (typeof input === "string") { var monthfield=input.split("/")[0]; var dayfield=input.split("/")[1]; var yearfield=input.split("/")[2]; } else { var monthfield=input.value.split("/")[0]; var dayfield=input.value.split("/")[1]; var yearfield=input.value.split("/")[2]; } var dayobj = new Date(yearfield, monthfield-1, dayfield); if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) alert("Invalid Day, Month, or Year range detected. Please correct and submit again."); else returnval=true; }catch (err) { print("Invalid Date Format. Please correct and submit again."); } if (returnval==false && typeof input === "object") input.select(); return returnval; }
run
|
edit
|
history
|
help
0
strCompression
Error
Mreee
rr
Rocket Science
Functions
H
color
MyProfile_Medalla.java
Javascript Basics