I want create a validation for date i don't know why output function `valid_date()` in ` $('.submit').submit(... alert(valid_date()); ... ` after click on button is `undefined`, how can fix it?
Code JavaScript:
    function valid_date() {
        $(document).delegate('input.date:text', 'keyup change', function () {
            var class_show = '.' + $(this).closest('div.auto_box2').find('div:last').attr('class');
            $val = $(this).val().replace(/[^\d]+/g, "").match(/\d{1,12}$/);
            var $this = $(this);
            val = $this.val();
            name = $this.closest('div.auto_box2').find('input').attr('name');
            url = $this.attr('class').split(" ")[0];
            filter = $this.attr('class').split(" ")[2];
            var class_age = '.' + $(this).closest('div.age').find('input[name="age"]').attr('class');
            if (filter == "limitdate") {
                dataObj = 'limit_date=' + val;
            } else {
                dataObj = 'date=' + val;
            }
            $(class_show).empty().attr('style', '');
            //alert(filter);
            if (val.match(/^\d\d\d\d\/\d\d\/\d\d$/)) {
                var result = true;
                $.ajax({
                    type: "POST",
                    dataType: "JSON",
                    url: url,
                    data: dataObj,
                    cache: false,
                    success: function (data) {
                        //alert(data);
                        if (data == null) {
                            $(class_show).attr('style', 'margin: 0 5px 0 0; color: #7E7E7E; background-color: #ffffec; height: 26px; padding: 2px 3px 0 3px; font-size: 13px;');
                            $(class_show).show().html('<b>Is wrong.<b>');
                            $(class_age).val('0');
                            $('.' + filter).css("background", "#ffc4c4");
                            result = false;
                        } else {
                            $(class_show).show().html('');
                            $(class_show).attr('style', 'margin: 0 5px 0 0; color: #7E7E7E; background-color: #ffffec; height: 26px; padding: 2px 3px 0 3px;')
                            $('<b>' + data.date + '<input name="' + name + '" value="' + data.date + '" style="display: none;"></b>').appendTo(class_show);
                            $(class_age).val(data['age']);
                            $('.' + filter).css("background", "#FFFFEC");
                        }
                    },
                    "error": function (x, y, z) {
                        // callback to run if an error occurs
                        alert("An error has occured:\n" + x + "\n" + y + "\n" + z);
                    }
                });
            } else {
                $('.' + filter).css("background", "#ffc4c4");
                result = false;
            }
            return result;
        });
    }
    //submit form ////////////////////////////////////////////////////////
    $('.submit').submit(function () {
        //ticket_check();
        var passed = true;
        alert(valid_date());
        passed = valid_date() && passed;
        //passed = autocomplet_valid() && passed;
        //passed = ticket_check() && passed;
        //passed = required_selectbox() && passed;
        //passed = required_valid() && passed;
        if (!passed) {
            $('#loadingDiv, #overlay').hide();
            return false;
        }
    });