got a question here..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • temmari
    New Member
    • Mar 2007
    • 1

    got a question here..

    if a user inputs a date in the text field witht the wrong format..how i can i make an error message that will catch the error that the input date format is wrong?
    please answer me..asap
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by temmari
    if a user inputs a date in the text field witht the wrong format..how i can i make an error message that will catch the error that the input date format is wrong?
    please answer me..asap
    You check the entered data against the format(s) that you allow and show a pop if it's wrong. Where are you getting problems?

    Comment

    • N002199B
      New Member
      • Feb 2007
      • 41

      #3
      Originally posted by temmari
      if a user inputs a date in the text field witht the wrong format..how i can i make an error message that will catch the error that the input date format is wrong?
      please answer me..asap
      It depends. How are you going to be passing the validations. Assuming it's from a jsp, this validation could be done via javascript at the user interface - webpage.

      Else, if u are to pass it strait to java, just surround the Date instantating line with a try catch block. After this you juss have to work on the program flow and java will catch the exception for you. It's up to you to ignore the date creation line or prompt the user for a valid date from there. For example -:
      Code:
      //BALALALALA CODE
      // CODE TO RECEIVE THE USER date INPUT
      String dateReceived = req.getParameter("myDate");
      java.sql.Date progDate = null;
      try{
           progDate  = java.sql.Date.valueOf(dateReceived);
      }catch(DateFormatException dtfe){
      //code for program flow after an invalid date is receved
      }
      If your date format is more persnalised and not the default ones of sql.Date, or util.Date, I suggest that you visit Regular Expressons to do the validation checks then.

      Comment

      Working...