For what it's worth, if you can think of a better (read: cleaner) way to do what I'm currently doing, please let me know :)
On Oct 28, 11:26 am, Validatorian <[EMAIL PROTECTED]> wrote: > I'm doing something similar to this > example:http://docs.jquery.com/Plugins/Validation/Methods/required#dependency... > > I have a date input field, and if you are under 13, it pops up another > field for parent's age.But unlike this example,I want the parent to be > required to be 18 or older.How would I set it up to require the input, > and require it to be over a certain age. > > It 's also important to note that the inputs are dates, not ages, so I > can't just do "min:18" because it 's more like "Tue Aug 29 2023 > 11:18:38 GMT-0700 (Pacific Daylight Time)" > > If needed, here's what I am currently doing: > > function checkAge(parent) { > var min_age = 13; > > if (parent) { > var dateArray = parent.split('/'); > min_age = 18; > } else { > var dateArray = $('#dateOfBirth').val().split('/'); > } > var year = dateArray[2]; > var month = dateArray[0] - 1; > var day = dateArray[1]; > > var theirDate = new Date(); > theirDate.setFullYear((parseInt(year) + min_age), month, day); > console.log(theirDate); > var today = new Date(); > console.log(today); > console.log(today - theirDate); > > if (today < theirDate) { > $('#parentsRequired').show(); > return true; > } else { > $('#parentsRequired').hide(); > return false; > } > > } > > .... > > dateOfBirth: { > required: function(element) { > var check = checkAge(); > return true; > }, > date: true}, > > parentsDateOfBirth: { > required: function(element) { > return checkAge($(element).val()); > }, > date: true > > },