function validAgeTest(el, value, callback) {
var StringDate = value;
if(/(\b\w{2}\b\/\b\w{2}\b\/\b\w{4}\b)|(\b\w{1}\b\/\b\w{1}\b\/\b\w{4}\b)|(\b\w{1}\b\/\b\w{2}\b\/\b\w{4}\b)|(\b\w{2}\b\/\b\w{1}\b\/\b\w{4}\b)/.test(StringDate) === true){
console.log('valid format')
var date = StringDate.split("/");
NewDate = new Date(date[2],date[1]-1,date[0]);//Date object
var now = new Date();
var ageraw = now - NewDate;
var age = ageraw/(365.25*86400*1000);
console.log(age);
if(age<=18){
el.attr('data-validation-callback-message','Πρέπει να είστε μεγαλύτερος από 18 ετών')
el.data('validation-callback-message','Πρέπει να είστε μεγαλύτερος από 18 ετών')
return false;
}
else if(value == ''){
el.attr('data-validation-callback-message','empty value')
el.data('validation-callback-message','empty value')
return false;
}
}
else{
el.attr('data-validation-callback-message','format error!')
el.data('validation-callback-message','format error!')
return false;
}
return true;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.