The goal is to show message for users that are less 25 years old. The personal ID consists of 081010333333, where 08year, 10month, 10date. I made code and it's very messy. So the question is: how to make it "right"? any advices and solutions are welcome. One on codepen and the code itself:
$('input').on('change keyup', function(i, el){
var d = new Date(),
getVal = $(this).val(),
getYear = $(this).val().slice(0,2),
getMonth = $(this).val().slice(2,4),
getDay = $(this).val().slice(4,6),
getCurrentYearFull = d.getFullYear(),
getCurrentMonth = ("0" + (d.getMonth() + 1)).slice(-2),
getCurrentDate = ("0" + (d.getDate())).slice(-2),
getCurrentYearShort = d.getFullYear().toString().slice(2,4);
if(getYear > getCurrentYearShort){
getYear = "19" + getYear
} else {
getYear = "20" + getYear
}
var yearDiff = getCurrentYearFull - getYear;
if (yearDiff >=10 && $('input').val().length >= 4) {
if(getCurrentMonth >= getMonth){
if (getCurrentDate >= getDay){
$(".check").text('good')
}
else {
$(".check").text('bad')
}
} else {
$(".check").text('bad')
}
} else {
$(".check").text('bad')
}
$('.test').text(yearDiff)
})
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<input type="text" value="120330"/>
<div class="check"></div>
<div class="test"></div>