Validate a year

Hi,
I'm using forms6i.
I have a text field in my form to enter Year. How can i programmatically check whether the year is valid or not?
I'm doing like this right now
Declare
      Format_Error EXCEPTION;
      PRAGMA EXCEPTION_INIT(Format_Error, -01830);
      conv_year Date;
Begin
           If      :PYEAR is null then
               Msg_Alert('Enter a Year!','I',FALSE);
          Else
                     conv_year := to_date(:PYEAR , 'YYYY');
          End if;
Exception
     When Format_Error then
     Msg_alert('Enter a Valid Year !','E',TRUE);
     When Others then
     Msg_Alert('Exception '||sqlerrm,'E',TRUE);
End;Is this the right way to check for a valid year?
Thanks

If your input field is/has to be VARCHAR2 try this:
Declare
conv_year Date;
function valid_year(pYr VARCHAR2) return boolean is
vTemp DATE;
begin
vTemp := to_date(pYr,'YYYY');
return TRUE;
exception
when others then
return FALSE;
end;
Begin
if not valid_year(:pyear)
then
Msg_Alert('Enter a Year!','I',FALSE);
Else
conv_year := to_date(:PYEAR , 'YYYY');
End if;
end;

Similar Messages

  • AGO function in OBIEE to display weekly sales data of this year vs last yea

    All,
    I would to create an analysis that display this year sales numbers vs last year by weekly
    I was able to do this at month level by specifying the offset value to 12 to the AGO function in repository.
    I am not able to do at week level.
    Can someone please help?
    Thanks

    Check the W_DAY_D or W_WEEK_D for number of weeks per year, validate the year/4 then its leap year then 53
    Use this in ago function at <<Number of Periods>>.
    I think you have to go for 53 based on these tables some times 54.

  • Coherence cannot handle year in dates of 9999 ?

    Hi,
    I have been running into an issue with dates in coherence. We have some data which specifies a date of 01/01/9999 to indicate that the date does not expire.
    However this results in errors when loading into coherence as follows:-
    java.io.IOException: year is likely out of range: 9999
    I then found this related thread:-
    Storing large DateTime values from .NET
    Is it really true that coherence cannot handle a valid date ???? Why would you possibly validate a year in the first place given 9999 is actually a valid year !.
    TIA
    Martin

    Hi,
    What is the code that causes the error? What version of Coherence are you using?
    I can serialize/deserialize the date you have without seeing any problems. For example...
    Calendar c = Calendar.getInstance();
    c.set(9999, Calendar.JANUARY, 1);
    Date d = c.getTime();
    ConfigurablePofContext pofContext = new ConfigurablePofContext("coherence-pof-config.xml");
    Binary b = ExternalizableHelper.toBinary(d, pofContext);
    Date d2 = (Date) ExternalizableHelper.fromBinary(b, pofContext);
    System.out.println(d2);The above code works fine when I ran it with Coherence 3.7.1.6
    If I have a class that implements PortableObject with a date field set to 1/1/9999 this also serializes without any problems.
    JK

  • Create a "Date" class & modify, ouput incorrect - why?

    hi,
    Would you mind explaining to me what i did wrong with my code...
    when i run the main() i get:
    ..today . : . tomorrow
    mm/dd/yyyy : mm/dd/yyyy
    12/28/1949 : 00/29/0000
    12/29/1949 : 00/29/0000
    12/30/1949 : 00/29/0000
    12/31/1949 : 00/29/0000
    12/32/1949 : 00/29/0000
    12/33/1949 : 00/29/0000
    Modify the Date class of Fig.8.8 to:
    provide a method nextDay to increment the day by one. The Date object should remain in a constant state. Write a driver program that test the nextDate method in a loop.
    // Fig. 8.8: Date.java
    // Declaration of the Date class.
    //package com.deitel.jhtp3.ch08;
    import javax.swing.JOptionPane;
    public class Date extends Object {
       private int month;  // 1-12
       private int day;    // 1-31 based on month
       private int year;   // any year
       private int nextMonth;  // 1-12
       private int nextDay;    // 1-31 based on month
       private int nextYear;   // any year
       // Constructor: Confirm proper value for month;
       // call method checkDay to confirm proper
       // value for day.
       public Date( int mn, int dy, int yr )
              month = checkMonth( mn );      // validate the month
          year  = checkYear( yr );       // validate the year
          day   = checkDay( dy );        // validate the day
          nextDay = nextDate( month,day,year);
          System.out.println(
             "Date object constructor for date " + toString() );
         //utility method to check month
         private int checkMonth( int testMonth )
              if ( testMonth > 0 && testMonth <= 12 ) // validate the month
             month = testMonth;
          else {
             month = 1;
             System.out.println( "Month " + testMonth +
                                " invalid. Set to month 1." );
          return testMonth;  // leave object in consistent state
         //utility method to check year
         private int checkYear( int testYear )
              if ( testYear > 0 && testYear <= 2002 )
             year = testYear;
          else {
             year = 2002;
             System.out.println( "Year " + testYear +
                                " invalid. Set to year 2002." );
          return testYear;  // leave object in consistent state
       // Utility method to confirm proper day value
       // based on month and year.
       private int checkDay( int testDay )
          int daysPerMonth[] = { 0, 31, 28, 31, 30,
                                 31, 30, 31, 31, 30,
                                 31, 30, 31 };
          if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
             return testDay;
          if ( month == 2 &&   // February: Check for leap year
               testDay == 29 &&
               ( year % 400 == 0 ||
                 ( year % 4 == 0 && year % 100 != 0 ) ) )
             return testDay;
          System.out.println( "Day " + testDay +
                              " invalid. Set to day 1." );
          return 1;  // leave object in consistent state
         private int nextDate( int mon, int da, int yer )
              //add one to day
              //does it start the next month
              //does it start the next year
          int daysEaMonth[] = { 0, 31, 28, 31, 30,
                                 31, 30, 31, 31, 30,
                                 31, 30, 31 };
              nextDay = da + 1;
                   if ( nextDay > daysEaMonth[month]){
                      nextDay = 1;
                      if (mon == 12)
                         nextMonth = 1;
                      else
                         nextMonth = mon + 1;
                      if (nextMonth == 1) nextYear = year + 1;
                   }//end of if nextDay
          return nextDay;
       // Create a String of the form month/day/year
       public String toString()
          { return month + "/" + day + "/" + year +
                   " : " + nextMonth + "/" + nextDay + "/"
                    + nextYear + "\n" ; }
    public static void main( String args[] )
       {   String result = "";
              //Date c = new Date();
          Date d = new Date( 12, 28, 1949 );
          //Date e = new Date( 7, 24, 1949 );
          for (int x = 1; x<6; x++ ){
                   d.day++;
                   result = result + d.toString();
          JOptionPane.showMessageDialog( null,
             //e.toString()+ d.toString(),
             result,
             "Testing Date Class",
             JOptionPane.INFORMATION_MESSAGE );
          System.exit( 0 );
    }//end of class Date
    *****************************************************************/

    ok, will change...
    Question regarding
    "You're not setting the values of nextMonth or nextYear anywhere."
    but i have class variables.....
    private int nextMonth; // <dont these values get assigned from the
    private int nextDay; // <function "nextDate", i mean, heck i thot
    private int nextYear; // <if they were class var's i could assign val
    private int nextDate( int mon, int da, int yer )
         nextDay = da + 1;
         if ( nextDay > daysEaMonth[month]){
            nextDay = 1;
            if (mon == 12)
               nextMonth = 1;
            else
               nextMonth = mon + 1;
            if (nextMonth == 1) nextYear = year + 1;

  • Extracting data through fn module to smartforms

    i am writing a select statement to extract the data from a table and that table i have to export to the smart form

    See the following ex:
    REPORT  zfi_credit_note  MESSAGE-ID       00.
    *--- Table declaration
    TABLES: bseg,
            t001,
            bkpf.
    TYPES: BEGIN OF TY_DOC.
            INCLUDE STRUCTURE ZFI_CREDIT_NOTE.
    TYPES: END OF TY_DOC.
    *--- Data declaration
    DATA: t_ssfcrescl TYPE ssfcrescl,
          t_ssfctrlop TYPE ssfctrlop,
          g_subrc     LIKE sy-subrc,
          fname       TYPE rs38l_fnam.
    DATA: IT_DOC TYPE STANDARD TABLE OF TY_DOC WITH HEADER LINE.
    SELECTION-SCREEN
    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: p_bukrs LIKE bkpf-bukrs OBLIGATORY.
    SELECT-OPTIONS: S_belnr FOR bkpf-belnr OBLIGATORY MATCHCODE OBJECT fmcj_fi_reference_debi.
    PARAMETERS: p_gjahr LIKE bkpf-gjahr OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN
    Validate Company code
    AT SELECTION-SCREEN ON p_bukrs.
      SELECT SINGLE * FROM t001 INTO t001
              WHERE bukrs EQ p_bukrs.
      IF sy-subrc NE 0.
        MESSAGE e368 WITH text-003.
      ENDIF.
    Validate Document number
    AT SELECTION-SCREEN ON S_belnr.
      SELECT SINGLE * FROM BKPF INTO BKPF
              WHERE bukrs EQ p_bukrs
                AND belnr IN S_belnr
                AND ( BLART = 'DG' or
                      BLART = 'ZN' ).
      IF sy-subrc NE 0.
        MESSAGE e368 WITH S_belnr ' ' text-002.
      ENDIF.
    Validate Fiscal year
    AT SELECTION-SCREEN ON p_gjahr.
      SELECT SINGLE * FROM bseg INTO bseg
              WHERE gjahr EQ p_gjahr.
      IF sy-subrc NE 0.
        MESSAGE e368 WITH text-004.
      ENDIF.
    START-OF-SELECTION
    START-OF-SELECTION.
      SELECT BELNR FROM BKPF INTO CORRESPONDING FIELDS OF TABLE IT_DOC WHERE BELNR IN S_BELNR.
    Call Smart form
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname           = 'ZCREDIT_NOTE'
        IMPORTING
          fm_name            = fname
        EXCEPTIONS
          no_form            = 1
          no_function_module = 2
          OTHERS             = 3.
      IF sy-subrc <> 0.
        MOVE sy-subrc TO g_subrc.
        CASE g_subrc.
          WHEN 1.
            MESSAGE e368 WITH 'No form exist'.
          WHEN 2.
            MESSAGE e368 WITH 'No Function Module'.
          WHEN OTHERS.
            " Do nothing.
        ENDCASE.
        EXIT.
      ENDIF.
      CALL FUNCTION fname
        EXPORTING
        ARCHIVE_INDEX              =
        ARCHIVE_INDEX_TAB          =
        ARCHIVE_PARAMETERS         =
         CONTROL_PARAMETERS         = t_ssfctrlop
        MAIL_APPL_OBJ              =
        MAIL_RECIPIENT             =
        MAIL_SENDER                =
        OUTPUT_OPTIONS             =
        USER_SETTINGS              = 'X'
          G_BUKRS                    = P_BUKRS
          G_GJAHR                    = P_GJAHR
      IMPORTING
        DOCUMENT_OUTPUT_INFO       =
         JOB_OUTPUT_INFO            = t_ssfcrescl
        JOB_OUTPUT_OPTIONS         =
        TABLES
          IT_DOC                     = IT_DOC
       EXCEPTIONS
         FORMATTING_ERROR           = 1
         INTERNAL_ERROR             = 2
         SEND_ERROR                 = 3
         USER_CANCELED              = 4
         OTHERS                     = 5
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

  • Help with constructor

    Hello, Im trying for hours and Im having trouble understanding why my code is not working. I added a private instance variable called birthDate that uses a class called Date(3 private int var. for day, month, year). I adjusted the constructor to have 3 more integer arguments to add in the Date. I would like to return the birth month of a person when i run it. This is what I have...any help is very much appreciated.
    public abstract class Employee {
       private String firstName;
       private String lastName;
       private String socialSecurityNumber;
       private Date birthDate;     //private instance variable birthDate(class Date)
       // constructor
       public Employee( String first, String last, String ssn, int bMonth, int bDay, int bYear)
          firstName = first;
          lastName = last;
          socialSecurityNumber = ssn;
              birthDate.day = bDay;
           birthDate.month = bMonth;
           birthDate.year = bYear;
    // public method getBirthMonth() - return the birth month of person.
       public int getBirthMonth()
         return bMonth;
       }As well, i would like to add a method that will check the persons month against the calender month and return either 0 or 100 to get a bonus.
    This is what i tried but not sure if it is correct...
    // method to calculate bonus
         public double bonus(int month)
              Calendar now = Calendar.getInstance();               // declare local system date
              int thisMonth = now.get(Calendar.MONTH);          // get this month, 0 for January
              System.out.print("This month is: " + thisMonth);      // print this month
              g.drawString("This month is: " + thisMonth, 25, 25); // print this month as used in applets
              if ( thisMonth == month)    // validate the month
              {  return 100;  }
              else { return 0; }
         }Can anyone help me solve this...Thank you and have a good day. :)

    this is my date class:
    public class Date {
       private int month;  // 1-12
       private int day;    // 1-31 based on month
       private int year;   // any year
       // constructor: call checkMonth to confirm proper value for month;
       // call checkDay to confirm proper value for day
       public Date( int theMonth, int theDay, int theYear )
          month = checkMonth( theMonth ); // validate month
          year = theYear;                 // could validate year
          day = checkDay( theDay );       // validate day
          System.out.println( "Date object constructor for date " +
             toDateString() );
       } // end Date constructor
       // utility method to confirm proper month value
       private int checkMonth( int testMonth )
          if ( testMonth > 0 && testMonth <= 12 )  // validate month
             return testMonth;
          else { // month is invalid
             System.out.println( "Invalid month (" + testMonth +
                ") set to 1." );
             return 1;  // maintain object in consistent state
       } // end method checkMonth
       // utility method to confirm proper day value based on month and year
       private int checkDay( int testDay )
          int daysPerMonth[] =
             { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
          // check if day in range for month
          if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
             return testDay;
          // check for leap year
          if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||
               ( year % 4 == 0 && year % 100 != 0 ) ) )
             return testDay;
          System.out.println( "Invalid day (" + testDay + ") set to 1." );
          return 1;  // maintain object in consistent state
       } // end method checkDay
       // return a String of the form month/day/year
       public String toDateString()
          return month + "/" + day + "/" + year;
    } // end class Date

  • 1 year ago i installed Elements 12 on my PC with a serial number.  Today i have installed Elements 12 also on my laptop. But,...there is a problem with validation of the serial number on my laptop. Is there a need to validate Elements  or will this progra

    One year ago i installed Elements 12 on my PC with a serial number and it was OK.
    Today i have installed Elements 12 also on my laptop.
    But,...there is a problem with validation of the serial number on my laptop. Is there a need to validate Elements  or will this program real disapeare in 7 days?
    Hans

    Hi,
    Since you already have one copy activated the serial number must be logged in your account details - I would first check that the one logged and the one you are attempting to enter are the same.
    You can check your account details by going to www.adobe.com and clicking on Manage Account. You need to sign in with your Adobe Id and then click on View All under Plans & Products. Next click on View your products and after a while it should produce your list.
    If there is a problem with the serial number, only Adobe can help you there (we are just users). Please see the response in this thread
    First of all, I would have to say that getting in touch with you is a nightmare and I am not at all happy that I can't just email or live chat with someone who can help!  I am not a technical person, I just want to be able to use Photoshop Elements and ge
    Brian

  • How can I validate date to be half year later than current date?

    Can anybody help me with validating date selected by user with Date picker?
    If the Date is later half year from today - it is valid, otherwise invalid. I need to keep focus within the field if invalid input supplied.
    Thanks inadvance,
    Peter.

    In essence time in javascript is stored as a long (just like in java) this means that increasing this number by 1000 increases the date by 1second.
    We know that 1 day = 24 hours = 1440 mins = 86400 seconds (*1000 for ms)
    So what you need to do is calculate the number of days you have during those months and multiply this by 86400000 and add this to the date.
    I would also suggest calculating the max time (date + 6months) up in front, if the user specifies a higher date (userdate - currentdate > date_in_6_months), it's actually invalid and you could just replace the userinput by your calculation. This way the end-user is never able to store a date further in time and your validation is already done. You could also try replacing when user_date < current_date, but thats up to you, i don't know your business-logic.
    If possible try to provide this data using XML binding, this way you could do the calculations in java/.net or whatever programming lanague you use. JavaScript is one of the most horrible environments to work with dates. It's just a hint.

  • I signed up with the wrong email address for itunes and have been using it for 2 years, now it wants me to validate the address, but I can't.  HELP

    Please help.  Is there anyway to change my email address on my apple id?

    Well, your first mistake was making a new Apple ID. You only needed to go into Manage your Apple ID and change the Apple ID from the Yahoo email to your new email. Then, all the purchases you made with that old Apple ID would still be tied to your updated Apple ID.
    As it is, you now have a totally new Apple ID, but the purchases you made with that old Apple ID are still (and will forever be) tied to it.
    Your best bet is to log into Manage your Apple ID with the old ID (regardless of what Yahoo did with it, it is still a functional Apple ID, unless you had that disable for security reasons). Once you have logged into it, change the password on it to match the password on your new ID. Then when you are asked for a password to update an app, it won't matter which of the two Apple IDs is displaying. You will just type in the same password and your app will be updated.
    Cheers,
    GB

  • Can FDM handle more than one year at a time?

    Hi,
    I'm trying to load a multi-load file through FDM with the target being an Essbase cube and the source being a text file. The file is for 36 months which crosses 3 years. The problem is Oracle support is saying FDM can only handle one calendar year at a time and we need to load 3 separate files.
    The file imports and validates ok. And the export only pushes data to the first year '2010' but it doesn't error out.
    Any ideas?

    If you use an excel file as the source, you can load all 36 periods.
    You can also modify the adaptor to support this action but I would caution you that doing so will cause support to no longer support your application without requiring you to import a non customized adaptor. This also has consequences for when upgrading.
    Let me add, FDM support is the best in the business. I have never had a situation where what they told me was incorrect. What you are trying to accomplish would be a custom solution that should be implemented by an experienced FDM resource that understands the impact of the customization.
    Edited by: TonyScalese on May 6, 2010 3:10 PM

  • Validate GL Account at SRM shopping cart at account assignment level

    Hi,
    In the SRM shopping cart system, at Account Assignment Overview level, is there any BADI or user exit or enhancement options to validate the GL Account when the account is selected/key-in?
    I try BADI for BBP_DETERMINE_ACCT, BBP_MESSAGES_BADI and BBP_ACC_CHECK_ICC. All is not trigger at Account Assignment level.
    Please advice.

    Hi,
    I have a similar requirement apart from all the validations done by BBP_DOC_CHECK_BADI  ,
    we have to add one more validation (check the asset acquisition date if it is less than the current fiscal year give error message).
    This has to done in R/3 .
    I checked for the exits in the FM BBP4X_CODINGBLOCK_CHECK_47A and found that there are no exits for this FM.
    PLEASE SUGGEST.Any help is appreciated.
    Regards,
    Rhea.

  • Validate Date Range - Javascript

    Hi Gang,
    This is close to a repost... but more of a followup to a
    thread that has
    already moved down everyones list.
    I have a pretty simple form validation routine I need to
    implement, but I
    don't know the Javascript syntax well enough to work it out
    (my background
    is VBscript, but this needs to be client side). I received
    some good URL's
    to check out some free scripts.. but unfortunately, I don't
    know javascript
    well enough to hack them up correctly.
    If someone can help out with a bit of code, it would be a
    huge help.
    What I need to do is validate a numeric range as well as not
    leaving the
    field blank.
    For example what is entered must be a number between 1900 and
    2006.
    Here is what I am using for the basic required function:
    The name of the form is "ThisForm_Right", and the field name
    is "DOB_Year"
    (to explain the piece in the code below)
    if (ThisForm_Right.DOB_Year.value=="")
    alert ("Please enter the YEAR of your DOB.");
    ThisForm_Right.DOB_Year.focus();
    return false;
    Can some kind sole help with a modified version to also check
    for an entered
    number range?
    I suspect some sort of "And" statement, Like
    If
    ThisForm_Right.DOB_Year.Value==""
    AND
    Year.Value NOT between (1900 and 2006)
    alert ("Please enter the YEAR of your DOB between 1900 and
    2006.");
    ThisForm_Right.DOB_Year.focus();
    return false;
    I just don't know the real syntax :>
    Thanks
    -D

    >thanks you so much for the code, I'll test it out and
    reply with >the
    >results.
    Shouldn't that be "Thanks so much for the Cod"?
    "Dave Bar" <[email protected]> wrote in message
    news:e28c7t$hk1$[email protected]..
    > ahh yes, you are right..
    > I should have said OR instead of AND.
    > If Field is blank OR range is not between 1900 &
    2006. Thanks for catching
    > and pointing that out.
    >
    > thanks you so much for the code, I'll test it out and
    reply with the
    > results.
    > Thanks
    > -Dave
    >
    >
    >
    >
    > "Lionstone" <[email protected]> wrote
    in message
    > news:e28b1a$fu5$[email protected]..
    >> That's probably because you asked for a fish to help
    you out
    >>
    >>> Can some kind sole help with a modified version
    to also check for an
    >>> entered
    >>> number range?
    >>
    >> and fish can't type.
    >>
    >> You're off on the logic though, since something is
    not likely to be both
    >> blank and outside a certain number range. If it's
    blank or outside the
    >> range, either condition is sufficient for an error,
    right?
    >> You also want to make sure that no letters, etc, are
    entered, because
    >> that will mess up your comparisons to the other
    numbers. Keeping in mind
    >> that javascript validation can be defeated by
    sneezing and you'll need to
    >> re-validate on the server, this will be closer to
    right (not tested).
    >>
    >> var ThisYear = ThisForm_Right.DOB_Year.value;
    >> ThisYear = ThisYear.replace(/[^/d]/g,"");
    >> if(ThisYear.length == 0)
    >> {
    >> alert("Please enter the year of your DOB.");
    >> ThisForm_Right.DOB_Year.focus();
    >> return false;
    >> }
    >> else
    >> {
    >> ThisYear = parseInt(ThisYear);
    >> if((ThisYear < 1900) || (ThisYear > 2006))
    >> {
    >> alert ("The year of your DOB must be between 1900
    and 2006.");
    >> ThisForm_Right.DOB_Year.focus();
    >> return false;
    >> }
    >> }
    >>
    >>
    >
    >

  • How to validate date using case statement.

    I have date like 022212. I split month,date,year using STUFF Function. Now, i have to validate month in range 01-12 and date in range 01-31.  Can some one help me with the query.
    Thanks, Shyam Reddy.

    That is not  date; it is apparently a string (we have no DDL because you are so rude). Any competent SQL programmer will use DATE.   You want help with a query, but there is no query.  
    CAST ('20' + SUBSTRING (crap_string_date, 5,2)+'-' + SUBSTRING (crap_string_date, 1,2) + '-' +  SUBSTRING (crap_string_date, 3,2)  AS DATE) AS redddy_screwed_up_date 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Who can tell how to validate a date in poor java?

    My programm can let user to input date in the default dateformat. Before save it to database I'd validate if the input is valid date. buf I can't find any function to do it both in java.util.Date and java.sql.Date, my program is as follow:
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); // in default Locale
    java.util.Date testdate;
    input = jtfInDate.getText().trim();
    if(!input.equals("")) {
    try {
    testdate = df.parse(input);
    } catch(ParseException pe) {
    JOptionPane.showMessageDialog(this,
    "<html><font color=red size=4>invalid date format</font></html>",
    "warning",
    JOptionPane.WARNING_MESSAGE);
    return false;
    System.out.println("indate" +testdate);
    If I input "dafafa" in the jtfInDate(is a JTextField),the DateFormat can detect that's invalid and throw ParseException. But when I input "9999-99-99", the DateFormat can parse it without Exception!!!
    and print out as "indate=Thu Jun 07 00:00:00 CST 10007", year 10007!!!!
    "9999-99-99" is obviously a invalid date format. Why DateFormat.parse() can think is OK?
    Is this the java's excellency????
    Could anyone tell me how to judge a string of date is valid?

    You can use the setLenient method to tell the DateFormat object to stop trying to help you out, this should go some way toward getting you where you need to go. Check the API docs out for that.
    Good Luck
    Lee
    PS: don't mind esran, he's not the sharpest tool in the shed, and is likely still trying to figure out the mess he documented in this thread:
    http://forum.java.sun.com/thread.jsp?thread=519291&forum=31&message=2479820
    So, I suppose a little slack is warrented

  • How to validate the date in my class

    Hi
    In my project with jsp and struts I need to validate the date field.
    So in the action class I want to validate the date that is the date is in dd/mm/year format?
    can anybody please give some idea to do this?
    Thank you so much.

    Here is a method that validates day/month/year using the Calendar class.
         public boolean validateDate(int day, int month, int year) {
              try {
                   Calendar cal = Calendar.getInstance();
                   cal.clear();
                   cal.setLenient(false);
                   cal.set(year, month-1, day);
                   // need to call getTime() to make the calendar compute/validate the date
                   cal.getTime();
                   return true;
              catch (IllegalArgumentException e) {               
                   return false;
         }

Maybe you are looking for