3

I am getting a string value from user and I want to check if the string is valid date or not?

Prabhakar
  • 402
  • 6
  • 20

2 Answers2

2

This works in XPages SSJS context:

var df = new java.text.DateFormat.getDateInstance();
df.setLenient(false);
try {
    var d  = df.parse(dateString);
    return true;
} catch (e) {
    return false;
}

This code returns true if dateString is a valid date string and false if not.

setLenient(false) is used to make a strong validation.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
0

try this function:

    function ifDate(date) {
        return !isNaN(Date.parse(date));
    }
abdulbasit
  • 1,856
  • 15
  • 17