Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client side - isDate function (formats) #9

Open
nunos7 opened this issue Mar 15, 2016 · 2 comments
Open

Client side - isDate function (formats) #9

nunos7 opened this issue Mar 15, 2016 · 2 comments

Comments

@nunos7
Copy link

nunos7 commented Mar 15, 2016

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

NS

@brentonlamar
Copy link

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.

@amustafa91
Copy link

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);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants