2
I have a form built with Swing
(Java) that has some fields, among them there is one that is the Date of Birth (a String that receives the value of a date and has a formatted field ##/##/####
.) which is represented by the variable jTFDataNascimento
which is a JFormattedTextField
.
How could you make sure the user doesn’t put absurd dates like:
11/20/2090 or 11/10/1890?
The only validation I do 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 as to whether the content is empty or not, it is possible?
There are no restrictions on the field being a String or date, I put String by practicality!
I have worked on some java web projects and doing this validation is something trivial on an 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 registered in the system and also see if that same date is greater than the highest date previously registered.
or better yet
the method takes three dates (Data, Data, Data, Data) and check if the Data is less than the Data or if the same date is greater than the Data.
public boolean validarData(LocalDate dataAtual, LocalDate dataRemota, LocalDate dataNascimento){
//codigo que não sei ainda...
return false;
}
See this example on Soen: Jformattedtextfield : input time Duration value
– user28595
There are two different doubts in the same question, follow another link to the second doubt, but I advise to separate the second doubt in another question; http://www.botecodigital.info/java/a-api-de-data-do-java-8/
– user28595
@Diegof No words old!! You gave me constructive tips!! This raises the morale of stackoverflow!!!
– Pena Pintada