Results 1 to 6 of 6

Thread: Validating Data in Java

  1. #1
    Join Date
    Jan 2010
    Posts
    119

    Validating Data in Java

    Hello,
    I have three data, DD the day, month MM YYYY year, and I want to test the logic that date. But I used the methods of Java DateFormat GregorianCalendar, but they only allow to test the format of the date, and though I respect for a data I can assign them values without any errors. Do you have any other alternative than this? Thank you.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Validating Data in Java

    This is a very simple code and I think this will help you

    Code:
    public void main (String args []) ( 
    CalTester CalTester tst = new (); 
    
    ytt int = 2001; 
    mtt int = 10; 
    dtt int = 18; 
    tst.testDate (ytt, mtt, dtt); 
    
    ytt = 2001; 
    mtt = 14; 
    dtt = 18; 
    tst.testDate (ytt, mtt, dtt); 
    
    ytt = -2001; 
    mtt = 7; 
    dtt = 21; 
    tst.testDate (ytt, mtt, dtt); 
    
    ytt = 2001; 
    mtt = 158; 
    dtt = 21; 
    tst.testDate (ytt, mtt, dtt);

  3. #3
    Join Date
    Mar 2010
    Posts
    182

    Re: Validating Data in Java

    Here is another code which may help you
    Code:
    try 
    ( 
    dtgeocal = new GregorianCalendar (year, nm - 1 day) / / 0 = January 
    
    dtgeocal.setLenient boundary (false) / / without this line, no possible exception 
    
    an dtgeocal.get int = (GregorianCalendar.YEAR); 
    nmb dtgeocal.get int = (GregorianCalendar.MONTH); 
    jrb dtgeocal.get int = (GregorianCalendar.DAY_OF_MONTH); 
    ) 
    catch (Exception e) 
    ( 
    e.printStackTrace (); 
    )

  4. #4
    Join Date
    Mar 2010
    Posts
    383

    Re: Validating Data in Java

    I want to get a date with a JTextField and save it in a MySQL database. I can add but the date is October 15, 1580, even if I put another date. for example code for this date is October 15, 1580, (c d2 and if I record in my database). How am I to insert a date of birth for any customer?

  5. #5
    Join Date
    May 2008
    Posts
    222

    Re: Validating Data in Java

    But when you say that you want to record in your database is to be recovered in a JTextField. What form is coming then? What format do you want to send? You have to have a way to send it to your base without or by date or by non Calendar, by doing a get of JTextField, and placing it in the desired shape before the transfer.

  6. #6
    Join Date
    May 2008
    Posts
    248

    Re: Validating Data in Java

    To enter a date specific (date of birth mentioned in your example, February 13, 1987):
    use it as
    Calendar c = new GregorianCalendar (int year, int month -1, int day);
    either:
    Calendar c = new GregorianCalendar (1987, 1, 13);

Similar Threads

  1. Problem validating TAILS download
    By sanctimonious-saliva in forum Operating Systems
    Replies: 3
    Last Post: 04-09-2013, 10:37 AM
  2. VB: Validating Username and Password In CSV File
    By admoore01 in forum Software Development
    Replies: 1
    Last Post: 26-11-2011, 05:25 PM
  3. Why my wireless is asking validating identity
    By Krishanu in forum Networking & Security
    Replies: 6
    Last Post: 16-10-2010, 02:46 PM
  4. How to do Validating and Sanitizing in PHP?
    By michaels in forum Software Development
    Replies: 4
    Last Post: 23-02-2010, 06:10 AM
  5. Validating Email in Java
    By KALYAN23 in forum Software Development
    Replies: 3
    Last Post: 04-11-2009, 05:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,276,293.40105 seconds with 17 queries