form validation date and time

#1
[eluser]TheoR74[/eluser]
what is the best way to setup on a form a date/time field and have it validated?

Thanks.

#2
[eluser]Rey Philip Regis[/eluser]
For me the simpliest way of doing it, is to find a javascript library to do it for me..There are lots of javascript libraries on the web and on of them is DOJO http://dojotoolkit.org

Actually if its possible I don't really like to code forms with validation manually cause it takes time rather than look for a javascript library, then find the one you need and use it in your application.

If you really want to do it manually why not use drop down boxes for the month - day - year - hour - minutes. All drop down boxes has a default value of blank meaning "" no value. Then use CI's form validation with "required" parameter.

Hope that helps..

#3
[eluser]fesweb[/eluser]
Here is a very good and flexible js datepicker.

Depending on your needs, you'll likely still want to do server-side validation to be thorough, using callback functions to supplement the form_validation library.

Good luck.

#4
[eluser]Unknown[/eluser]
For me fastest way to do it using date picker using jquery used to get date if you do that u can force user to enter date/time of your format.
Or other way to do it is Regular Expression :coolsmile:

#5
[eluser]Kamarg[/eluser]
I make use of the jquery date picker like the others have suggested. However, since we all know that you can't trust user input, you still need to validate the date on the server side. For that I've extended the form validation library and added the date rule below. There are better date regex validation functions out there but for my purposes it doesn't matter if the user gives me a date such as 99/99/0001 as the date fields are merely display information and not used for any type of logic.
Code:
function date($str) {
    return (bool) preg_match("(\d{1,2}\/\d{1,2}\/\d{4})", $str);
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.