fieldValidators = ({
byr: function(y) {
if (!/^\d{4}$/.test(y)) return false;
if (parseInt(y) < 1920 || parseInt(y) > 2002) return false;
return true;
},
iyr: function(y) {
if (!/^\d{4}$/.test(y)) return false;
if (parseInt(y) < 2010 || parseInt(y) > 2020) return false;
return true;
},
eyr: function(y) {
if (!/^\d{4}$/.test(y)) return false;
if (parseInt(y) < 2020 || parseInt(y) > 2030) return false;
return true;
},
hgt: function(h) {
const matches = h.match(/^(\d+)(in|cm)$/);
if (!matches) return false;
const hgt = parseInt(matches[1]);
if (matches[2] == 'cm') {
if (hgt < 150 || hgt > 193) return false;
} else {
if (hgt < 59 || hgt > 76) return false;
}
return true;
},
hcl: function(hcl) {
return /^\#[0-9a-f]{6}$/.test(hcl);
},
ecl: function(ecl) {
return ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth'].includes(ecl);
},
pid: function(pid) {
return /^\d{9}$/.test(pid);
}
})