code: public static Date parseDate(String format, String value)
          throws ParseException {
  
          SimpleDateFormat sdFormat = new SimpleDateFormat(format);
          sdFormat.setLenient(false);
          ParsePosition pp = new ParsePosition(0);
          Date d = sdFormat.parse(value, pp);
  
          /*
          a date value such as: 12/01/2005x will not cause a parse error,
          use the parse position to detect this case.
          */
          if (d == null || pp.getIndex() < value.length())
              throw new ParseException("Parsing date value, "
                  + value
                  + ", failed at index " + pp.getIndex(), pp.getIndex());
          else return d;
      }
docs: Parse a date value into the specified format.  Pay special attention to the case of the value
  having trailing characters, ex. 12/02/2005xx which will not cause the parse of the date to fail
  but should be still treated as an error for our purposes.
  
  @param format Format string for the date.
  @param value A String containing the date value to parse.
  @return A Date instance if the parse was successful.
  @throws ParseException If the value is not a valid date.