Repository: identique/idnumbers (language: python)

Issue:
id number for Netherlands
https://en.wikipedia.org/wiki/National_identification_number#Netherlands


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 64466757..491e4e6c 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,7 @@ print(id_data['citizenship'])
 * MEX - Mexico
 * MYS - Malaysia
 * NGA - Nigeria
+* NLD - Netherlands
 * NZL - New Zealand
 * PHL - Philippine
 * SGP - Singapore
diff --git a/idnumbers/nationalid/NLD.py b/idnumbers/nationalid/NLD.py
new file mode 100644
index 00000000..a83b0653
--- /dev/null
+++ b/idnumbers/nationalid/NLD.py
@@ -0,0 +1,45 @@
+import re
+from types import SimpleNamespace
+from .util import validate_regexp
+
+
+def normalize(id_number: str) -> str:
+    return re.sub(r'[.]', '', id_number)
+
+
+class NationalID:
+    """
+    Netherlands National ID number
+    Burgerservicenummer (BSN) (Citizen Service Number)
+    https://en.wikipedia.org/wiki/National_identification_number#Netherlands
+    https://nl.wikipedia.org/wiki/Burgerservicenummer
+    """
+    METADATA = SimpleNamespace(**{
+        'iso3166_alpha2': 'NL',
+        # length without insignificant chars
+        'min_length': 9,
+        'max_length': 9,
+        'parsable': False,
+        'checksum': True,
+        'regexp': re.compile(r'(?!0000.00.000)^\d{4}[.]\d{2}[.]\d{3}$')
+
+    })
+
+    @staticmethod
+    def validate(id_number: str) -> bool:
+        """
+        Validate the NLD id number
+        """
+        if not validate_regexp(id_number, NationalID.METADATA.regexp):
+            return False
+        return NationalID.checksum(id_number)
+
+    MAGIC_MULTIPLIER = [9, 8, 7, 6, 5, 4, 3, 2]
+
+    @staticmethod
+    def checksum(id_number: str) -> bool:
+        normalized = normalize(id_number)
+        number_list = [int(char) for char in list(normalized[:-1])]
+        total = sum([value * NationalID.MAGIC_MULTIPLIER[index] for (index, value) in enumerate(number_list)])
+        checksum = total % 11
+        return str(total % 11) == normalized[-1] if checksum != 10 else False


Test patch:
diff --git a/idnumbers/nationalid/test_NLD.py b/idnumbers/nationalid/test_NLD.py
new file mode 100644
index 00000000..e4a1b24f
--- /dev/null
+++ b/idnumbers/nationalid/test_NLD.py
@@ -0,0 +1,18 @@
+from unittest import TestCase, main
+
+from idnumbers.nationalid import NLD
+
+
+class TestARGValidation(TestCase):
+    def test_normal_case(self):
+        self.assertTrue(NLD.NationalID.validate('1234.56.782'))
+        self.assertTrue(NLD.NationalID.validate('1112.22.333'))
+
+    def test_error_case(self):
+        self.assertFalse(NLD.NationalID.validate('1234#56.792'))
+        self.assertFalse(NLD.NationalID.validate('12.345.6783'))
+        self.assertFalse(NLD.NationalID.validate('0000.00.000'))
+
+
+if __name__ == '__main__':
+    main()