|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Isidor128 Smarty Regular
Joined: 27 Jul 2004 Posts: 35 Location: France
|
Posted: Fri Aug 06, 2004 11:37 am Post subject: SmartyValidate and pre Unix date validation |
|
|
Hi
For thus like me who are old as dino's
Born before 01/01/1970 I mean we need to use a special function to verify if a Birthdate is valid. Also MySQL provide a very nice option for dates to, handle partial date definition (year only month year....)
Using Basic Smarty PlugIn or validation could fail
I've designed this code I use in my site to verify the Date format.
[php:1:f93e7c798f]<?php
/**
* test if a value is a valid Gergorian date
* Valid Format are : jj/mm/aaaa (10)
* mm/aaaa (7)
* jj/mm (5)
* aaaa (4)
*
* @param string $value the value being tested
* @param boolean $empty if field can be empty
* @param array params validate parameter values
* @param array formvars form var values
*/
function smarty_validate_criteria_isGDate($value, $empty, &$params, &$formvars) {
if (strlen($value) == 0) return $empty;
else $date = explode("/",$value);
if (strlen($value) == 10) return checkdate($date[1],$date[0],$date[2]);
elseif (strlen($value) == 7) return checkdate($date[0],1,$date[1]);
elseif (strlen($value) == 5) return checkdate($date[1],$date[0],1900);
elseif (strlen($value) == 4) return checkdate(1,1,$value);
else return -1;
}
?>[/php:1:f93e7c798f]
Dates are considered to be in European Format, could be possible to handle also ISO Format or the strange US Format
Regards |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|