/** * <p>Validate using the specified <code>Locale</code>. * * @param value The value validation is being performed on. * @param pattern The pattern used to format the value. * @param locale The locale to use for the Format, defaults to the default * @return <code>true</code> if the value is valid. */ @Override public boolean isValid(String value, String pattern, Locale locale) { Object parsedValue = parse(value, pattern, locale, (TimeZone)null); return (parsedValue == null ? false : true); }
/** * <p>Checks if the value is valid against a specified pattern.</p> * * @param value The value validation is being performed on. * @param pattern The pattern used to validate the value against, or the * default for the <code>Locale</code> if <code>null</code>. * @param locale The locale to use for the date format, system default if null. * @param timeZone The Time Zone used to parse the date, system default if null. * @return The parsed value if valid or <code>null</code> if invalid. */ protected Object parse(String value, String pattern, Locale locale, TimeZone timeZone) { value = (value == null ? null : value.trim()); if (value == null || value.length() == 0) { return null; } DateFormat formatter = (DateFormat)getFormat(pattern, locale); if (timeZone != null) { formatter.setTimeZone(timeZone); } return parse(value, formatter); }
/** * Test Invalid Dates with "pattern" validation */ public void testPatternInvalid() { for (int i = 0; i < patternInvalid.length; i++) { String text = i + " value=[" +patternInvalid[i]+"] passed "; Object date = validator.parse(patternInvalid[i], "yy-MM-dd", null, null); assertNull("validateObj() " + text + date, date); assertFalse("isValid() " + text, validator.isValid(patternInvalid[i], "yy-MM-dd")); } }
/** * Test Invalid Dates with "locale" validation */ public void testLocaleInvalid() { for (int i = 0; i < localeInvalid.length; i++) { String text = i + " value=[" +localeInvalid[i]+"] passed "; Object date = validator.parse(localeInvalid[i], null, Locale.US, null); assertNull("validateObj() " + text + date, date); assertFalse("isValid() " + text, validator.isValid(localeInvalid[i], Locale.US)); } }
/** * Test Valid Dates with "pattern" validation */ public void testPatternValid() { for (int i = 0; i < patternValid.length; i++) { String text = i + " value=[" +patternValid[i]+"] failed "; Object date = validator.parse(patternValid[i], "yy-MM-dd", null, null); assertNotNull("validateObj() " + text + date, date); assertTrue("isValid() " + text, validator.isValid(patternValid[i], "yy-MM-dd")); if (date instanceof Calendar) { date = ((Calendar)date).getTime(); } assertEquals("compare " + text, patternExpect[i], date); } }
/** * Test Valid Dates with "locale" validation */ public void testLocaleValid() { for (int i = 0; i < localeValid.length; i++) { String text = i + " value=[" +localeValid[i]+"] failed "; Object date = validator.parse(localeValid[i], null, Locale.US, null); assertNotNull("validateObj() " + text + date, date); assertTrue("isValid() " + text, validator.isValid(localeValid[i], Locale.US)); if (date instanceof Calendar) { date = ((Calendar)date).getTime(); } assertEquals("compare " + text, patternExpect[i], date); } }
/** * Test Invalid Dates with "locale" validation */ public void testFormat() { // Create a Date or Calendar Object test = validator.parse("2005-11-28", "yyyy-MM-dd", null, null); assertNotNull("Test Date ", test); assertEquals("Format pattern", "28.11.05", validator.format(test, "dd.MM.yy")); assertEquals("Format locale", "11/28/05", validator.format(test, Locale.US)); }
/** * <p>Validate using the specified <code>Locale</code>. * * @param value The value validation is being performed on. * @param pattern The pattern used to format the value. * @param locale The locale to use for the Format, defaults to the default * @return <code>true</code> if the value is valid. */ public boolean isValid(String value, String pattern, Locale locale) { Object parsedValue = parse(value, pattern, locale, (TimeZone)null); return (parsedValue == null ? false : true); }
/** * <p>Validate using the specified <code>Locale</code>. * * @param value The value validation is being performed on. * @param pattern The pattern used to format the value. * @param locale The locale to use for the Format, defaults to the default * @return <code>true</code> if the value is valid. */ @Override public boolean isValid(String value, String pattern, Locale locale) { Object parsedValue = parse(value, pattern, locale, (TimeZone)null); return (parsedValue == null ? false : true); }
/** * <p>Validate using the specified <code>Locale</code>. * * @param value The value validation is being performed on. * @param pattern The pattern used to format the value. * @param locale The locale to use for the Format, defaults to the default * @return <code>true</code> if the value is valid. */ @Override public boolean isValid(String value, String pattern, Locale locale) { Object parsedValue = parse(value, pattern, locale, (TimeZone)null); return (parsedValue == null ? false : true); }
/** * <p>Checks if the value is valid against a specified pattern.</p> * * @param value The value validation is being performed on. * @param pattern The pattern used to validate the value against, or the * default for the <code>Locale</code> if <code>null</code>. * @param locale The locale to use for the date format, system default if null. * @param timeZone The Time Zone used to parse the date, system default if null. * @return The parsed value if valid or <code>null</code> if invalid. */ protected Object parse(String value, String pattern, Locale locale, TimeZone timeZone) { value = (value == null ? null : value.trim()); if (value == null || value.length() == 0) { return null; } DateFormat formatter = (DateFormat)getFormat(pattern, locale); if (timeZone != null) { formatter.setTimeZone(timeZone); } return parse(value, formatter); }
/** * <p>Checks if the value is valid against a specified pattern.</p> * * @param value The value validation is being performed on. * @param pattern The pattern used to validate the value against, or the * default for the <code>Locale</code> if <code>null</code>. * @param locale The locale to use for the date format, system default if null. * @param timeZone The Time Zone used to parse the date, system default if null. * @return The parsed value if valid or <code>null</code> if invalid. */ protected Object parse(String value, String pattern, Locale locale, TimeZone timeZone) { value = (value == null ? null : value.trim()); if (value == null || value.length() == 0) { return null; } DateFormat formatter = (DateFormat)getFormat(pattern, locale); if (timeZone != null) { formatter.setTimeZone(timeZone); } return parse(value, formatter); }
/** * <p>Checks if the value is valid against a specified pattern.</p> * * @param value The value validation is being performed on. * @param pattern The pattern used to validate the value against, or the * default for the <code>Locale</code> if <code>null</code>. * @param locale The locale to use for the date format, system default if null. * @param timeZone The Time Zone used to parse the date, system default if null. * @return The parsed value if valid or <code>null</code> if invalid. */ protected Object parse(String value, String pattern, Locale locale, TimeZone timeZone) { value = (value == null ? null : value.trim()); if (value == null || value.length() == 0) { return null; } DateFormat formatter = (DateFormat)getFormat(pattern, locale); if (timeZone != null) { formatter.setTimeZone(timeZone); } return parse(value, formatter); }