+ 1

How to validate a date from user input?

I want to validate the birthdate from user input. I'm using HTML 5 and Internet Explorer 8. I want to ensure that the date is in mm/dd/yyyy format and not more than the present date.

19th Apr 2018, 6:12 AM
Ynelle Kyle Novicio
Ynelle Kyle Novicio - avatar
4 Respostas
+ 2
Is there a requirement to use IE8? It does not have great support for HTML5. Chrome, Firefox or Microsoft Edge are what you should be using. That said. <input type="text" name="date" placeholder="mm/dd/yyyy" pattern="(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/\d{4}" required /> The html5 will do the pattern matching on the input and get you mm/dd/yyyy when you submit the form to php have the following: $todayTime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $formTime = strtotime($_POST['date']); if ($formTime > $todayTime) { // error because submitted date greater than today }
19th Apr 2018, 8:52 AM
Adam
Adam - avatar
+ 1
$arr = explode(”/”, $date); if(checkdate($arr[0], $arr[1], $arr[2])) { /*True*/ }
19th Apr 2018, 8:37 AM
Toni Isotalo
Toni Isotalo - avatar
0
split month, date and day to array and use checkdate function
19th Apr 2018, 8:34 AM
Toni Isotalo
Toni Isotalo - avatar
0
yeah, thanks guys I already figure it out... but thanks for the suggestions and advices.... For now I just only have IE8 and no chrome installed in my Uncle's laptop.
19th Apr 2018, 5:40 PM
Ynelle Kyle Novicio
Ynelle Kyle Novicio - avatar