1

There are a "Date" button and a "Submit" on my activity. When I click on "Date" button, a date picker is shown.The selected date becomes the text of the "Date" button.

On the click of "Submit" button, the text on the "Date" button gets stored in a sqlite database.

I just want a validation on click of "Submit" button that the text of "Date" button is a valid date.

Can someone help me, please?

P R
  • 105
  • 9

2 Answers2

1

try this:

  public static boolean isValidDate(String inDate) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    try {
      dateFormat.parse(inDate.trim());
    } catch (ParseException pe) {
      return false;
    }
    return true;
  }

use it as:

System.out.println(isValidDate(your_string));
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
0

You can check the date is matched with your desired date pattern or not. Check this out: Date Validation in Android

Community
  • 1
  • 1
Leo
  • 44
  • 1
  • 2
  • 8