def validate_result()

in presidio-analyzer/presidio_analyzer/predefined_recognizers/au_tfn_recognizer.py [0:0]


    def validate_result(self, pattern_text: str) -> bool:
        """
        Validate the pattern logic e.g., by running checksum on a detected pattern.

        :param pattern_text: the text to validated.
        Only the part in text that was detected by the regex engine
        :return: A bool indicating whether the validation was successful.
        """
        # Pre-processing before validation checks
        text = self.__sanitize_value(pattern_text, self.replacement_pairs)
        tfn_list = [int(digit) for digit in text]

        # Set weights based on digit position
        weight = [1, 4, 3, 7, 5, 8, 6, 9, 10]

        # Perform checksums
        sum_product = 0
        for i in range(9):
            sum_product += tfn_list[i] * weight[i]
        remainder = sum_product % 11
        if remainder == 0:
            result = True
        else:
            result = None
        return result