Is String a Date - Node.js Date

Node.js examples for Date:Date Format

Description

Is String a Date

Demo Code

String.prototype.isDate = function() {
    var checkStr = this;
    for (i = 0; i < checkStr.length; i++) {
        ch = checkStr.charAt(i);// w  w w  .j a v a2 s  .  c om
        if ((i == 4) || (i == 7)) {
            if (ch != '-') {
                return (false);
            }
        } else {
            if (ch < '0' || ch > '9') {
                return (false);
            }
            if ((i == 5 && ch > '1') || (i == 8 && ch > '3')) {
                return (false);
            }
        }
    }
    return (true);
}

Related Tutorials