View previous topic :: View next topic |
Author |
Message |
davemenc Smarty Rookie
Joined: 18 Mar 2005 Posts: 6
|
Posted: Fri Mar 18, 2005 7:15 am Post subject: SmartyValidate: isCCExpDate validation doesn't work!? |
|
|
I'm working with the example in the README file and I can't get the thing to agree that ANY date is valid for credit card expiration field.
The code looks to me like it should accept a valid month, a non numeric character, and a valid year, provided the date represented by the month+year is in the future.
But I've tried "08/08" and "8/2006" and a lot more besides and it never seems to agree that I've got a valid date in the future.
Please show me the error of my ways... I will be happy if someone can show me just one string that it will accept.
Dave |
|
Back to top |
|
mux Smarty n00b
Joined: 18 Mar 2005 Posts: 2
|
Posted: Fri Mar 18, 2005 7:33 am Post subject: |
|
|
I couldn't get that to work, either.
I really like the approach SmartyValidate is using, and I'm thinking about using it, but the fact that the example doesn't work does not instill confidence ... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 18, 2005 2:31 pm Post subject: |
|
|
Its a bug. Here is the fix:
Code: | function smarty_validate_criteria_isCCExpDate($value, $empty, &$params, &$formvars) {
if(strlen($value) == 0)
return $empty;
if(!preg_match('!^(\d+)\D+(\d+)$!', $value, $_match))
return false;
$_month = $_match[1];
$_year = $_match[2];
if(strlen($_year) == 2)
$_year = substr(date('Y', time()),0,2) . $_year;
$_month = (int) $_month;
$_year = (int) $_year;
if($_month < 1 || $_month > 12)
return false;
if(date('Y',time()) > $_year)
return false;
if(date('Y',time()) == $_year && date('m', time()) > $_month)
return false;
return true;
} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 18, 2005 2:43 pm Post subject: |
|
|
mux wrote: | I couldn't get that to work, either.
I really like the approach SmartyValidate is using, and I'm thinking about using it, but the fact that the example doesn't work does not instill confidence ... |
There are a lot of folks using SmartyValidate successfully. I think the ccExpDate criteria is one that no one has put to use yet (including myself) and consequently, no one has reported the problem until now.
btw, the CVS version of SmartyValidate takes a little different approach, moving the validation criteria to the PHP side, leaving only presentation (error messages) in the template. |
|
Back to top |
|
mux Smarty n00b
Joined: 18 Mar 2005 Posts: 2
|
Posted: Fri Mar 18, 2005 5:44 pm Post subject: |
|
|
In the CVS version, can you still do validation in the Smarty template, or is the PHP-side method replacing that?
I'm going to keep SmartyValidate in mind; however, I think I need something more mature for my current project.
Thanks for your help! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Mar 18, 2005 6:08 pm Post subject: |
|
|
Either way should work fine. |
|
Back to top |
|
davemenc Smarty Rookie
Joined: 18 Mar 2005 Posts: 6
|
Posted: Fri Mar 18, 2005 8:08 pm Post subject: |
|
|
[quote="mohrt"]Its a bug. Here is the fix:
snip...[/quote]
Aha! So it was doing a string comparison instead of a numeric comparison. I looked and looked but just couldn't find it! It was driving me CRAZY! :)
Thanks much
Dave |
|
Back to top |
|
|