Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.text.SimpleDateFormat;
  2. import java.util.Date;
  3.  
  4. public class DataValidation
  5. {
  6. public boolean checkIfStringEmpty(String validDate)
  7. {
  8. // Check if date is null
  9. if (validDate == null || validDate == "")
  10. {
  11. return false;
  12. }
  13. else
  14. {
  15. return true;
  16. }
  17. }
  18. public boolean checkStringSize(String validDate)
  19. {
  20. // Check if date is null
  21. if (validDate.length() >= 0 && validDate.length() <= 255)
  22. {
  23. return true;
  24. }
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30.  
  31. public Date newDate(String validDate)
  32. {
  33. if(checkIfStringEmpty(validDate) && checkStringSize(validDate) == true)
  34. {
  35. // Date Format
  36. SimpleDateFormat sdfrmt = new SimpleDateFormat("dd/MM/yyyy");
  37. sdfrmt.setLenient(false);
  38. // Create Date object and parses String into date
  39.  
  40.  
  41. try
  42. {
  43. Date javaDate = sdfrmt.parse(validDate);
  44. }
  45. catch (Exception e)
  46. {
  47. return null;
  48. }
  49. return validDate;
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement