Repository: identique/idnumbers (language: python)

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


Discussion / hints:

Fix patch:
diff --git a/idnumbers/nationalid/USA.py b/idnumbers/nationalid/USA.py
new file mode 100644
index 00000000..d326013e
--- /dev/null
+++ b/idnumbers/nationalid/USA.py
@@ -0,0 +1,32 @@
+import re
+from types import SimpleNamespace
+
+from .util import validate_regexp
+
+
+class NationalID:
+    """
+    United States national ID number format
+    Social Security number (SSN)
+    https://en.wikipedia.org/wiki/National_identification_number#United_States
+    https://www.geeksforgeeks.org/how-to-validate-ssn-social-security-number-using-regular-expression/
+    """
+    METADATA = SimpleNamespace(**{
+        'iso3166_alpha2': 'US',
+        # length without insignificant chars
+        'min_length': 9,
+        'max_length': 9,
+        # has parse function
+        'parsable': False,
+        # has checksum function
+        'checksum': False,
+        # regular expression to validate the id
+        'regexp': re.compile("^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$")
+    })
+
+    @staticmethod
+    def validate(id_number: str) -> bool:
+        """
+        Validate USA id number
+        """
+        return validate_regexp(id_number, NationalID.METADATA.regexp)


Test patch:
diff --git a/idnumbers/nationalid/test_USA.py b/idnumbers/nationalid/test_USA.py
new file mode 100644
index 00000000..c70ffa43
--- /dev/null
+++ b/idnumbers/nationalid/test_USA.py
@@ -0,0 +1,21 @@
+from unittest import TestCase, main
+from idnumbers.nationalid import USA
+
+
+class TestUSAValidation(TestCase):
+    def test_normal_case(self):
+        self.assertTrue(USA.NationalID.validate('012-12-0928'))
+
+    def test_error_case(self):
+        self.assertFalse(USA.NationalID.validate('987-12-0928'))
+        self.assertFalse(USA.NationalID.validate('666-12-0000'))
+
+    def test_with_regex(self):
+        self.assertRegex('012-12-0928', USA.NationalID.METADATA.regexp)
+
+    def test_with_metadata(self):
+        self.assertIsNotNone(USA.NationalID.METADATA)
+
+
+if __name__ == '__main__':
+    main()