List of usage examples for org.apache.commons.validator GenericTypeValidator formatCreditCard
public static Long formatCreditCard(String value)
From source file:org.apache.struts.validator.FieldChecks.java
/** * Checks if the field is a valid credit card number. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently * being performed.//from w w w. j ava2 s. c o m * @param field The <code>Field</code> object associated with the * current field being validated. * @param errors The <code>ActionMessages</code> object to add errors * to if any validation errors occur. * @param validator The <code>Validator</code> instance, used to access * other field values. * @param request Current request object. * @return true if valid, false otherwise. */ public static Object validateCreditCard(Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator, HttpServletRequest request) { Object result = null; String value = null; value = evaluateBean(bean, field); if (GenericValidator.isBlankOrNull(value)) { return Boolean.TRUE; } result = GenericTypeValidator.formatCreditCard(value); if (result == null) { errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field)); } return (result == null) ? Boolean.FALSE : result; }
From source file:org.megatome.frame2.validator.CommonsFieldValidator.java
/** * Validate a value as a credit card number. * //from w w w. j a va 2 s.co m * @param value * The value to validate * @param va * The validator action * @param errors * Errors object to populate * @param field * The field to validate * @return Formatted credit card value, or null if validation fails. */ public static Long validateCreditCard(String value, ValidatorAction va, Errors errors, Field field) { if (value == null) { return null; } Long result = null; result = GenericTypeValidator.formatCreditCard(value); if (result == null) { addError(va, errors, field); } return result; }
From source file:org.springmodules.commons.validator.FieldChecks.java
/** * Checks if the field is a valid credit card number. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed.//from w w w . j av a 2s. c o m * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return The credit card as a Long, a null if invalid, blank, or null. */ public static Long validateCreditCard(Object bean, ValidatorAction va, Field field, Errors errors) { Long result = null; String value = extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { result = GenericTypeValidator.formatCreditCard(value); if (result == null) { rejectValue(errors, field, va); } } return result; }
From source file:org.springmodules.validation.commons.FieldChecks.java
/** * Checks if the field is a valid credit card number. * * @param bean The bean validation is being performed on. * @param va The <code>ValidatorAction</code> that is currently being * performed.//from www. ja va2 s . co m * @param field The <code>Field</code> object associated with the current * field being validated. * @param errors The <code>Errors</code> object to add errors to if any * validation errors occur. * -param request * Current request object. * @return The credit card as a Long, a null if invalid, blank, or null. */ public static Long validateCreditCard(Object bean, ValidatorAction va, Field field, Errors errors) { Long result = null; String value = FieldChecks.extractValue(bean, field); if (!GenericValidator.isBlankOrNull(value)) { result = GenericTypeValidator.formatCreditCard(value); if (result == null) { FieldChecks.rejectValue(errors, field, va); } } return result; }