Files

30 lines
909 B
Python

#!/usr/bin/env python3
"""Simple email validator utility."""
import re
# RFC 5322 inspired regex (simplified but practical)
EMAIL_REGEX = re.compile(
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
)
def is_valid_email(email: str) -> bool:
"""Return True if email matches basic valid email pattern."""
if not email or not isinstance(email, str):
return False
return bool(EMAIL_REGEX.match(email))
def validate_email(email: str) -> dict:
"""Return validation result with details."""
return {
"email": email,
"valid": is_valid_email(email),
"reason": "Valid email format" if is_valid_email(email) else "Invalid email format"
}
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
for email in sys.argv[1:]:
result = validate_email(email)
print(f"{email}: {result['valid']} - {result['reason']}")