AlphaWolf Posted December 31, 2011 Share Posted December 31, 2011 Hi, I'm using the form data type 'date', and trying to verify it. It seems a little too complicated to check that it's in the correct format (with "/" between day/month/year), unless I use regular expression, which I don't know much about and seems feels like there's an alternate solution or it's not necessary. Currently, the script accepts DD*MM*YYYY, where * is any character, since it just strips the 3rd and 6th character and checks the day/month/year using checkdate(). I'm not even sure if this is a problem. I am giving the user a "verify" page, where I could put it in the correct format (DD/MM/YYYY), but is that enough? Feel like I'm missing something here, so any feedback would be great Quote Link to comment https://forums.phpfreaks.com/topic/254141-best-way-to-take-date-input-from-user/ Share on other sites More sharing options...
laffin Posted December 31, 2011 Share Posted December 31, 2011 I like them pop up javascript calendars myself. regex for date matching isnt very hard preg_match('@^\d{2}[/-]\d{2}[/-]\d{4}$@',$date); Quote Link to comment https://forums.phpfreaks.com/topic/254141-best-way-to-take-date-input-from-user/#findComment-1302915 Share on other sites More sharing options...
Andy-H Posted December 31, 2011 Share Posted December 31, 2011 Just use 3 input boxes <form method="post"> Date (d/m/Y): <input size="2" maxlength="2" title="Day of month" name="day" > <input size="2" maxlength="2" title="Month of year" name="month" > <input size="4" maxlength="4" title="Year" name="Year" > </form> I also like to use jQuery mouse wheel to scroll through days/months/years and a pop-up calendar, I wrote an extension to do both but it's on my work computer Quote Link to comment https://forums.phpfreaks.com/topic/254141-best-way-to-take-date-input-from-user/#findComment-1302918 Share on other sites More sharing options...
Pikachu2000 Posted December 31, 2011 Share Posted December 31, 2011 The 'best' approach, IMHO, is to use a jQuery datepicker, with <select> fields as the <noscript> backup, using the names of the months as the label part of the <option>s, then just use checkdate to validate the input. Quote Link to comment https://forums.phpfreaks.com/topic/254141-best-way-to-take-date-input-from-user/#findComment-1302921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.