java - The Calendar setLenient method doesn't allow the check of the sanity of the year field -


i used method check id date entered user valid or not:

  private boolean isthisdatevalid(date datetovalidate) {     calendar cal = calendar.getinstance();     if (datetovalidate == null) {         return false;     }      cal.setlenient(false);     cal.settime(datetovalidate);     try {         cal.gettime();     } catch (exception e) {         return false;     }     return true; } 

the problem when user writes wrong year (big year) doesn't throw exception example : 12/09/2016666

should check sanity of year field in seperate method.

even though far present, 2016666 still valid year. it's 2 million years now, can see why might not want in lots of contexts, strange date validator suggest not legitimate date. incorrect behavior.

if want additional validation (such ensuring year field not exceed current year) need , throw proper exception.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -