I'm trying to make a JavaScript function to validate the month and year from a field. The format of the date on the field is mm/yyyy and the function that validates it's the one below:
function validateVencimento(){
var valid = true;
var currentTime = new Date();
var actualMonth = currentTime.getMonth() + 1;
var actualYear = currentTime.getFullYear();
vencimento = vencimento.replace('///g', '');
var month = parseInt(vencimento.substring(0, 2),10);
var year = parseInt(vencimento.substring(2, 6),10);
if((month < 1) || (month > 12)) valid = false;
if((year < actualYear)) valid = false;
if((year < actualYear) && (month < actualMonth)) valid = false;
if(valid == false){
vencimento.addClass("error");
vencimentoInfo.text("A validade do cartao esta invalida!");
vencimentoInfo.addClass("error");
return false;
}
else{
vencimento.removeClass("error");
vencimentoInfo.text("");
vencimentoInfo.removeClass("error");
return true;
}
}
After i enter the date on the field i call the function above on blur, but the Chrome console returns the error Uncaught TypeError: Object # has no method 'replace'.