/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. * @return true if the value can be converted to a Date. */ public static boolean isDate(String value, String datePattern, boolean strict) { // TODO method isValid() not yet supported in routines version return org.apache.commons.validator.DateValidator.getInstance().isValid(value, datePattern, strict); }
/** * <p>Checks if the field is a valid date. The <code>Locale</code> is * used with <code>java.text.DateFormat</code>. The setLenient method * is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param locale The locale to use for the date format, defaults to the * system default if null. * @return true if the value can be converted to a Date. */ public static boolean isDate(String value, Locale locale) { return DateValidator.getInstance().isValid(value, locale); }
/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. * @return true if the value can be converted to a Date. */ public static boolean isDate(String value, String datePattern, boolean strict) { return DateValidator.getInstance().isValid(value, datePattern, strict); }
/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. * @return true if the value can be converted to a Date. */ @GwtIncompatible("incompatible method") public static boolean isDate(String value, String datePattern, boolean strict) { // TODO method isValid() not yet supported in routines version return org.apache.commons.validator.DateValidator.getInstance().isValid(value, datePattern, strict); }
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { if (value != null) { String val = value.toString(); if (org.apache.commons.validator.DateValidator.getInstance().isValid(val, this.getFormat(), this.getStrict()) == false) { String errorMessage = MessageFormat.format(BundleUtil.getString(Bundle.APPLICATION, INVALID_DATE), new Object[] { this.getFormat() }); throw new ValidatorException(new FacesMessage(errorMessage)); } } }