| | Stumble It! | Add to Mixx! | | diigo it | | Slashdot |

Friday, June 5, 2009

Simple Javascript Date Validation

A quick Google search for "Javascript date validation" resulted in several solid hits, but each had custom functions and blocks of code to copy/paste ... it kinda made me go barf. I didn't want all that overhead just to check a variable to make sure it held a date value.

So here's what I came up with. I don't know if it will work in all situations, but it serves my purposes quite well:
if (!Date.parse(variable)) {
 alert("Not an acceptable date.");
 return false;
}
I hope it meets your needs as well =)

Enjoy!

0 comments: