[program-java] Re: date validation

  • From: "Corbett, James" <James.Corbett@xxxxxxxxxxxxx>
  • To: <program-java@xxxxxxxxxxxxx>
  • Date: Thu, 22 Jan 2009 15:12:30 -0500

Anna:

Why make it complex if you don't have to.... It works, it's clean and
best of all it's free.

J. 

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Anna Giller
Sent: January 22, 2009 14:55
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Jim:

Thank you for this routine, but I have similar one.
I'm looking for validation using Java classes like DateFormat,
SimpleDate or any other one.

Thanks,
Anna
-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Thursday, January 22, 2009 2:18 PM
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: date validation

Anna:

Using date format of YYYY/MM/DD 

try{
                                int m =
Integer.valueOf(repPeriodEndDate.substring(5, 7)).intValue();
                                int d =
Integer.valueOf(repPeriodEndDate.substring(8)).intValue();

                                if(m==1 || m==3 || m==5 || m==7 || m==8
|| m==10 || m==12){
                                        if(d==31){
                                                dayValidation = true;
                                        }
                                }else if(m==4 || m==6 || m==9 || m==11){
                                        if(d==30){
                                                dayValidation = true;
                                        }

                                }else if(m==2){
                                        if(d==28 || d==29){
                                                dayValidation = true;
                                        }

                                }
                        }catch(NumberFormatException nfe){
                                nfe.printStackTrace();
                        } 

-----Original Message-----
From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Anna Giller
Sent: January 22, 2009 13:39
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] date validation

Jim:

 

Do you have a date validation routine?

I have one, it's ugly enough. It checks the value of the month, then the
value of the day, compares it with the array of valid values.

I need more professional one, that uses Java classes.

 

I was also looking for a numeric field validation, but just found one.

And want to share it with our people.

It's neat, isn't it?

I'm looking for a date validation routine in the similar style.

 

Thank you and the code follows.

Anna 

 

  int number=0;   

      while (number == 0) {   

    String input=JOptionPane.showInputDialog("\n\tEnter numeric
value.");   

    try{   

number=Integer.parseInt(input);   

    }catch(NumberFormatException nfe)   

    {   

Number = 0;   

    }   

 





Other related posts: