import java.util.regex.Matcher
......
.........
boolean isValidDate(String dates){
//String DATE_PATTERN = "(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d)"; // for simple
String DATE_PATTERN = "(((0[13578]|1[02])\\/(0[1-9]|[12]\\d|3[01])\\/((19|[2-9]\\d)\\d{2}))|((0[13456789]|1[012])\\/(0[1-9]|[12]\\d|30)\\/((19|[2-9]\\d)\\d{2}))|(02\\/(0[1-9]|1\\d|2[0-8])\\/((19|[2-9]\\d)\\d{2}))|(02\\/29\\/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))"
// detail solve for 31 problems/ leap year problem
Pattern pattern = Pattern.compile(DATE_PATTERN);
Matcher matcher = pattern.matcher(dates);
if(!matcher.matches()){
return true;
}
else {
return false;
}
}
System.out.println(isValidDate(06/20/2012)); // true
help from .....link
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন