foolproof icon indicating copy to clipboard operation
foolproof copied to clipboard

Client side - isDate function (formats)

Open nunos7 opened this issue 8 years ago • 2 comments

Hi, the isDate function (mvcfoolproof.unobtrusive.js) not work with dd/MM/yyyy format... What are the supported formats?

NS

nunos7 avatar Mar 15 '16 12:03 nunos7

Hi @nunos7, it appears that the isDate function uses a regex to check for valid formats. This format expects MM/dd/yyyy or MM-dd-yyyy.

brentonlamar avatar Oct 25 '16 18:10 brentonlamar

Hi,

@nunos7 I Solved this issue, but my issue was with GreaterThan by adding moment JS into my project then i made the following changes to the client script "mvcfoolproof.unobtrusive.js":

var isDate = function (input) {
        // mm/dd/yyyy
        //var dateTest = new RegExp(/(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/);

        //dd/mm/yyyy
        var dateTest = new RegExp(/((0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/[12]\d{3})/);
        return dateTest.test(input);
    };
if (isDate(value1)) {
        value1 = moment(value1, 'DD/MM/YYYY');
        value2 = moment(value2, 'DD/MM/YYYY');
    }
 switch (operator) {
        case "EqualTo": if (value1 == value2) return true; break;
        case "NotEqualTo": if (value1 != value2) return true; break;
        case "GreaterThan":
            if (typeof value1 === 'object' && value1._isAMomentObject !== 'undefined') {
                if (value1.isAfter(value2)) {
                    return true;
                }
            }
            else if (value1 > value2) {
                return true;
            }
            
            break;
        case "LessThan": if (value1 < value2) return true; break;
        case "GreaterThanOrEqualTo": if (value1 >= value2) return true; break;
        case "LessThanOrEqualTo": if (value1 <= value2) return true; break;
        case "RegExMatch": return (new RegExp(value2)).test(value1); 
        case "NotRegExMatch": return !(new RegExp(value2)).test(value1);
    }

amustafa91 avatar Jan 15 '19 14:01 amustafa91