Expanding on @Kal's answer, here's a utility method which you can use with any formatter to do "strict" parsing (uses apache commons StringUtils):
public static Object parseStrict(Format fmt, String value)
throws ParseException
{
ParsePosition pos = new ParsePosition(0);
Object result = fmt.parseObject(value, pos);
if(pos.getIndex() < value.length()) {
// ignore trailing blanks
String trailing = value.substring(pos.getIndex());
if(!StringUtils.isBlank(trailing)) {
throw new ParseException("Failed parsing '" + value + "' due to extra trailing character(s) '" +
trailing + "'", pos.getIndex());
}
}
return result;
}