You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Niall Pemberton (JIRA)" <ji...@apache.org> on 2006/07/19 15:25:19 UTC

[jira] Updated: (VALIDATOR-153) [validator] add "isFuture" validator for credit card expiration dates

     [ http://issues.apache.org/jira/browse/VALIDATOR-153?page=all ]

Niall Pemberton updated VALIDATOR-153:
--------------------------------------

    Component/s: Routines

> [validator] add "isFuture" validator for credit card expiration dates
> ---------------------------------------------------------------------
>
>                 Key: VALIDATOR-153
>                 URL: http://issues.apache.org/jira/browse/VALIDATOR-153
>             Project: Commons Validator
>          Issue Type: Improvement
>          Components: Routines
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Ralf Hauser
>            Priority: Minor
>
> as a complement to creditcard:
> - no credit card will be accepted past the expiration date
> assumption: the input calendar is of the form "yyyy-mm"
>     public static boolean isFuture(Object bean, ValidatorAction va,
>             Field field, ActionMessages errors, HttpServletRequest request) {
>         String value = ValidatorUtils.getValueAsString(bean, field
>                 .getProperty());
>         if (!GenericValidator.isBlankOrNull(value)) {
>             try {
>                 Date now = new Date(System.currentTimeMillis());
>                 Date input = null;
>                 try {
>                     //take the last of the month
>                     int month = Integer.parseInt(value.substring(5, 7));
>                     int year = Integer.parseInt(value.substring(0, 4));
>                     GregorianCalendar cal = new GregorianCalendar(year, month,
>                             1);//astonishingly creates the last day of the
> month, but that's what we need.
> //                    log.debug(new
> java.util.Date(cal.getTimeInMillis()).toGMTString());
>                     input = new java.util.Date(cal.getTimeInMillis());
> //                    log.debug(input.toGMTString());
>                 } catch (Exception e) {
>                     log.debug(e.getMessage());
>                     e.printStackTrace();
>                     return false;
>                 }
>                 if (!input.after(now)) {
>                     errors.add(field.getKey(), Resources.getActionMessage(
>                             request, va, field));
>                     return false;
>                 }
>             } catch (Exception e) {
>                 errors.add(field.getKey(), Resources.getActionMessage(request,
>                         va, field));
>                 return false;
>             }
>         } else {
>             //return false;//if field is required
>         }
>         return true;
>     }
> and in validator-rules.xml
>       <validator name="isFuture"
>             classname="org.apache.struts.validator.FieldChecks"
>                method="isFuture"
>          methodParams="java.lang.Object,
>                        org.apache.commons.validator.ValidatorAction,
>                        org.apache.commons.validator.Field,
>                        org.apache.struts.action.ActionMessages,
>                        javax.servlet.http.HttpServletRequest"
>               depends=""
>                   msg="error.notFuture" />

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org