This is kinda driving me crazy, maybe its just one of those days.
I have this If loop that I feel like its extremely redundant but I cant find a way to make it shorter
function validateYear (valfield, infofield, required)
{
var stat = commonCheck (valfield, infofield, required);
if (stat != proceed) return stat;
var tfld = trim(valfield.value);
var yfld = trim(valfield.length);
var Year = /^[0-9]{1,3}$/
if (!Year.test(tfld)) {
msg (infofield, "warn", "ERROR: not a valid year");
setfocus(valfield);
return false;
}
if (!valfield == "") {
if (!valfield == "") {
if (yfld<4) {
msg (infofield, "warn", "ERROR: Please insert 4 digits");
setfocus(valfield);
} else if (yfld>4) {
msg (infofield, "warn", "ERROR: Please insert only 4 digits");
setfocus(valfield);
} else if (tfld>2020) {
msg (infofield, "warn", "ERROR: Please check your Data");
setfocus(valfield);
}
return false;
} else if (!valfield == "") {
if (tfld<1940) {
msg (infofield, "warn", "Please check yout Data");
} else {
msg (infofield, "warn", "");
}
return true;
}
}
}