I have a form built with Swing
(Java) that has some fields, among them there is one that is the Birth Date (a String that receives the value of a date and has a formatted field ##/##/####
.) is represented by the variable jTFDataNascimento
which is a JFormattedTextField
.
How could you prevent the user from placing absurd dates such as: 11/20/2090 or 11/10/1890 ?
The only validation I make is to check if the fields are empty:
if(jTFDataNascimento.getText().equals(" / / "))...
I also wanted to validate the dates as to their values and not validate only if the content is empty or not, is it possible?
There are no restrictions on whether the field is a String or a date, so I put String for convenience!
I have already worked on some java web projects and doing this validation is something trivial on a html5 page, everything I learned about dates in java is about the java7 version, I think in java8 this is simpler to do.
I think there should be a code that receives a date and check if it is less than a date previously entered in the system and also see if that date is larger than the earlier date previously registered.
or better still
the method receives three dates (currentTime, dataRemota, DateTime) and checks whether theTimeTimeTime is less than the currentTimeTime or if thatTimeTime is greater than theTimeTimeTimeTime.
public boolean validarData(LocalDate dataAtual, LocalDate dataRemota, LocalDate dataNascimento){
//codigo que não sei ainda...
return false;
}