Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class DataValidation
- {
- public boolean checkIfStringEmpty(String validDate)
- {
- // Check if date is null
- if (validDate == null || validDate == "")
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public boolean checkStringSize(String validDate)
- {
- // Check if date is null
- if (validDate.length() >= 0 && validDate.length() <= 255)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public Date newDate(String validDate)
- {
- if(checkIfStringEmpty(validDate) && checkStringSize(validDate) == true)
- {
- // Date Format
- SimpleDateFormat sdfrmt = new SimpleDateFormat("dd/MM/yyyy");
- sdfrmt.setLenient(false);
- // Create Date object and parses String into date
- try
- {
- Date javaDate = sdfrmt.parse(validDate);
- }
- catch (Exception e)
- {
- return null;
- }
- return validDate;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement