Date validator is not failing when it should
- fix pattern:
SimpleDateFormat("MMyyyy")
- it add up the months:
new java.text.SimpleDateFormat("MMyyyy").parse("122000"); = Fri Dec 01 00:00:00 CET 2000
new java.text.SimpleDateFormat("MMyyyy").parse("132000"); = Mon Jan 01 00:00:00 CET 2001
new java.text.SimpleDateFormat("MMyyyy").parse("785454"); = Fri Jun 01 00:00:00 CEST 5460
new java.text.SimpleDateFormat("MMyyyy").parse("015454"); = Sun Jan 01 00:00:00 CET 5454
- the only exception you'll have to expect is
ParseException - if the beginning of the specified string cannot be parsed.
(see docs)
And the right solution (from comment):
setLenient
documentation and except
From the docs Throws: NullPointerException - if text or pos is null.
It looks like the parse method throws exception only if the value given is null.
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html