How to make HTML Input Box accept date strictly in format dd/MM/yyyy? Alternatively, any PHP code to pass entered date in this format to MySQL?
The html input field can't be forced to do such a thing. You can either let the user enter what he wants and then check on server side with php if the format matches.
Or you use jQuery and the jQuery Validation plugin (javascript) to already provide client-side a validation before submitting the form. e.g. like this
$("#myform").validate({
rules: {
field: {
required: true,
date: true
}
}
});
But you still need to check the format server-side as the user could have javascript disabled.
You can use this jquery script to mask the input...
And then use this PHP script:
$date = '10/11/2009';
echo date('d-m-Y', strtotime($date)); // outputs 10/11/2009
...to ensure your input is correct.
The best way to do it is both on the client and server. On the client, JavaScript code would validate that the input is in the right format. You can either write your own validation code or use something like jquery validation. On the server, PHP code would validate the date again before inserting it into the database.
at the JS side /[0-3][0-9]/[01][0-2]/\d{4}/.test(input_value)
should do the job.
use 3 drop down menu for day, month and year in html...... then put all the 3 inputs to an array in php and use explode() function...