Created
January 14, 2015 15:46
-
-
Save miwebguy/2b90d0280ea9e9488a7c to your computer and use it in GitHub Desktop.
Check Date Format Front and Back
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
| /**Check Date Input on Server**/ | |
| $date_regex = '/^(19|20)\d\d[\-\/.](0[1-9]|1[012])[\-\/.](0[1-9]|[12][0-9]|3[01])$/'; | |
| // Check date input | |
| if(isset($_POST['start'])) { | |
| if (preg_match($date_regex,$_POST['start']) && preg_match($date_regex,$_POST['end'])) { | |
| $_start = $_POST['start']; | |
| $_end = $_POST['end']; | |
| } else { | |
| die("Invalid Date Format"); | |
| } | |
| } | |
| <!--Check Input in Field--> | |
| <label for="Start" class="db">Start</label> | |
| <input type="date" name="start" id="Start" value="${start}" | |
| pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> | |
| <label for="End" class="db">End</label> | |
| <input type="date" name="end" id="End" value="${end}" | |
| pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Valid datetime "/^([1-2][0-9]{3})-([0-1][0-9])-([0-3][0-9])([TZ\s]{1})([0-5][0-9]):([0-5][0-9])$/"