From b245307f903d8eee53e880c3d68b77ee32d07003 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 27 Nov 2022 16:14:33 -0500 Subject: added ssn and mac validators --- src/edify/library/__init__.py | 2 ++ src/edify/library/mac.py | 16 ++++++++++++++++ src/edify/library/ssn.py | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 src/edify/library/mac.py create mode 100644 src/edify/library/ssn.py (limited to 'src') diff --git a/src/edify/library/__init__.py b/src/edify/library/__init__.py index 62d6528..5f091e8 100644 --- a/src/edify/library/__init__.py +++ b/src/edify/library/__init__.py @@ -13,3 +13,5 @@ from .uuid import uuid from .zip import zip from .guid import guid from .password import password +from .ssn import ssn +from .mac import mac diff --git a/src/edify/library/mac.py b/src/edify/library/mac.py new file mode 100644 index 0000000..9a8cf8f --- /dev/null +++ b/src/edify/library/mac.py @@ -0,0 +1,16 @@ +import re + +mac_address_validate_pattern = "^(?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2})$" + +def mac(mac: str) -> bool: + """Validate a MAC (IEEE 802) address. + + Args: + mac (str): The MAC address to validate. + + Returns: + bool: True if the MAC address is valid, False otherwise. + """ + if not isinstance(mac, str): + return False + return bool(re.match(mac_address_validate_pattern, mac)) diff --git a/src/edify/library/ssn.py b/src/edify/library/ssn.py new file mode 100644 index 0000000..8f42de6 --- /dev/null +++ b/src/edify/library/ssn.py @@ -0,0 +1,16 @@ +import re + +ssn_validate_pattern = "^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$" + +def ssn(ssn: str) -> bool: + """Validate a Social Security Number (SSN). + + Args: + ssn (str): The SSN to validate. + + Returns: + bool: True if the SSN is valid, False otherwise. + """ + if not isinstance(ssn, str): + return False + return bool(re.match(ssn_validate_pattern, ssn)) -- cgit v1.2.3