RE: [PHP] validate date

2002-12-19 Thread John W. Holmes
> If a user inputs a date into a form, what function can I use to
validate
> that he put in a valid date?
> I want to use checkdate but that needs the date split up into day,
month
> year.
> Anyone have an easy way of doing this?

You have to specify a date format to your users, or at least assume a
certain amount of formats. If you don't do this, then there's no way to
validate it, because any amount of variations exist of date formats. 

If you require a mm/dd/yy format, then just break it apart and validate
each element. You'll basically have to write your own function, or
possibly use strtotime() to see if it returns a result. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] validate date

2002-12-19 Thread Manuel Ochoa

Here is a funtion that I use.
A user can enter a date in any of the following ways:
01 01 03
01-01-03
1-1-03
01-1-2003
1-01/03
1/1 03  you get the idea...
This function will standardize the date and make sure it's valid. If invalid it 
returns "ERROR"
function fixdate($data){
 $aux[0]="";
 $aux[1]="";
 $aux[2]="";
 $z=0;
 for($i=0; $i wrote:If a user inputs a date into 
a form, what function can I use to validate
that he put in a valid date?
I want to use checkdate but that needs the date split up into day, month
year.
Anyone have an easy way of doing this?
Thanks,
Diana


RE: [PHP] validate date

2002-12-19 Thread Jon Haworth
Hi Diana,

> If a user inputs a date into a form, what function can I 
> use to validate that he put in a valid date?

You can't. Here are two dates in two different formats. Only one is valid.

  - 13/04/01
  - 13/04/01

Can you spot which is which?

> I want to use checkdate but that needs the date split up 
> into day, month year. Anyone have an easy way of doing this?

You could try separate drop-downs: one for day (with numbers 1-31), one for
month (with names) and one for years (whatever you need). This gives you
three variables that you can easily pass to checkdate().

Don't fall into the trap of thinking that if you put some text on your form
saying "please enter dates in mm-dd-yy format" that that's what you'll get,
unless you *really* know your audience.

Cheers
Jon



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php