i using following design in order validate age input (must greater 18):
the form following:
<div class="col-md-2 form-group"> <div class="input-group date"> <form:input path="legal_resp.birth_date" class="form-control datepicker" placeholder ="ηη/µµ/εεεε" data-validbirthdate="true"/> <span class="input-group-addon btn"> <span class="glyphicon glyphicon-calendar"></span></span> </div> <div class="help-block with-errors"></div> <form:errors path="legal_resp.birth_date" cssstyle="color: #ff0000;"/> </div> the options pass argument .validator following:
var options={ custom: { validbirthdate: function (input) { var str= input.val(); if(str == '') return true; var parts = str.split('/'); if (parts.length < 3) return false; else { var day = parseint(parts[0]); var month = parseint(parts[1]); var year = parseint(parts[2]); if (isnan(day) || isnan(month) || isnan(year)) { return false; } if (day < 1 || year < 1) return false; if(month>12||month<1) return false; if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && day > 31) return false; if ((month == 4 || month == 6 || month == 9 || month == 11 ) && day > 30) return false; if (month == 2) { if (((year % 4) == 0 && (year % 100) != 0) || ((year % 400) == 0 && (year % 100) == 0)) { if (day > 29) return false; } else { if (day > 28) return false; } } var d = new date(year, month-1, day); var agedifms = date.now() - d.gettime(); var agedate = new date(agedifms); // miliseconds epoch var age = math.abs(agedate.getutcfullyear() - 1970); if(age<18) return false; return true; } } i have following question:
i want exted function in order take input 2 different forms (2 age inputs) , compare them. understand need argument function. how can achieve this?
Comments
Post a Comment