How to Validate
Date Format
I'm developing a user detail
submition form in which I have to get users date of birth.
Gaurav Jain
I've attached the file to check
for invalid date.. lets say the date format s mm/dd/yyyy...
With reagards to the second prob:::: what I have understood is that, if the user does not attempt any quesiton u want to throw an error,...is this what you want to handle?? with this assumption, I want to get an info from you... Do you have a checkbox to indicate if the question has been attempted or not?? Or is there any other way by which you say if the question is attempted or not?? Based on this I think we can try to get the question collection... if it is a checkbox try to iterate thro' that collection and check if the checkbox is set to true for all questions and then throw an error msg.. Do get back if you got any doubts.. public static boolean testDate(String str) { int Jan = 31; int Mar = 31; int Apr = 30; int May = 31; int Jun = 30; int Jul = 31; int Aug = 31; int Sep = 30; int Oct = 31; int Nov = 30; int Dec = 31; boolean flag = true; StringTokenizer st = new StringTokenizer(str, "/"); int month = Integer.parseInt(st.nextToken()); int day = Integer.parseInt(st.nextToken()); int year = Integer.parseInt(st.nextToken()); if ((month > 12) && (month < 100)) { flag = false; } switch (month) { case 1: if (day > Jan) { flag = false; } break; case 2: if ((year % 4) == 0) { if (day > 29) { flag = false; } } else { if (day > 28) { flag = false; } } case 3: if (day > Mar) { flag = false; } break; case 4: if (day > Apr) { flag = false; } break; case 5: if (day > May) { flag = false; } break; case 6: if (day > Jun) { flag = false; } break; case 7: if (day > Jul) { flag = false; } break; case 8: if (day > Aug) { flag = false; } break; case 9: if (day > Sep) { flag = false; } break; case 10: if (day > Oct) { flag = false; } break; case 11: if (day > Nov) { flag = false; } break; case 12: if (day > Dec) { flag = false; } break; } return flag; }Kiruthiga
Do you have a Java Problem?
Java Books
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|