/// <summary> /// Whether this passport is valid. /// </summary> /// <returns></returns> public bool IsValidPassport() { if (!HasRequiredProperties) { return(false); } bool byr = Byr >= 1920 && Byr <= 2002; bool iyr = Iyr >= 2010 && Iyr <= 2020; bool eyr = Eyr >= 2020 && Eyr <= 2030; string unit = Hgt.Substring(Hgt.Length - 2); bool hgt = false; if (int.TryParse(Hgt.Substring(0, Hgt.Length - 2), out int value)) { if (unit == "cm") { hgt = value >= 150 && value <= 193; } else if (unit == "in") { hgt = value >= 59 && value <= 76; } } bool ecl = EyeColours.Contains(Ecl); bool hcl = Regex.IsMatch(Hcl, "#([0-9]|[a-f]){6}$"); bool pid = Regex.IsMatch(Pid, "[0-9]{9}$"); return(byr && iyr && eyr && hgt && hcl && ecl && pid); }
private bool IsHgtValid() { if (Hgt != null) { if (Hgt.EndsWith("cm")) { var length = int.Parse(Hgt.Substring(0, Hgt.Length - 2)); return(150 <= length && length <= 193); } else if (Hgt.EndsWith("in")) { var length = int.Parse(Hgt.Substring(0, Hgt.Length - 2)); return(59 <= length && length <= 76); } } return(false); }
private bool ValidHgt() { if (Hgt.Length < 4) { return(false); } string unit = Hgt.Substring(Hgt.Length - 2); int length = int.Parse(Hgt.Substring(0, Hgt.Length - 2)); if (unit == "cm") { return(length >= 150 && length <= 193); } if (unit == "in") { return(length >= 59 && length <= 76); } return(false); }