Created
September 13, 2013 22:54
-
-
Save kharmabum/6557109 to your computer and use it in GitHub Desktop.
text date input validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isValidDateLiteral: function (input){ | |
| var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Basic check for format validity | |
| if (!input.match(validformat)) return false; | |
| var monthfield=input.split("/")[0]; | |
| var dayfield=input.split("/")[1]; | |
| var yearfield=input.split("/")[2]; | |
| var dayobj = new Date(yearfield, monthfield-1, dayfield); | |
| if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) { | |
| return false; | |
| } else { | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment