Skip to content

Address Validator Project Enhancement: Added Comprehensive Email Validation #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
95 changes: 81 additions & 14 deletions Address Validator/AddressValidator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,83 @@
def addressVal(address):
dot = address.find(".")
at = address.find("@")
if (dot == -1):
print("Invalid")
elif (at == -1):
print("Invalid")
else:
print("Valid")
import re
import dns.resolver
import idna

# Regular expression for basic email syntax validation
email_regex = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'

def is_valid_email(email):
"""
Validates an email address through multiple checks.

Args:
email (str): The email address to validate.

Returns:
bool: True if the email is valid, False otherwise.
"""
# Check if the email contains '@'
if '@' not in email:
return False

# Split the email into local and domain parts
try:
local_part, domain_part = email.split('@')
except ValueError:
return False

# Check length constraints for local and domain parts
if len(local_part) > 64 or len(domain_part) > 255 or len(email) > 320:
return False

# Perform basic syntax validation
if not re.match(email_regex, email):
return False

print("This program will decide if your input is a valid email address")
while(True):
print("A valid email address needs an '@' symbol and a '.'")
x = input("Input your email address:")
# Validate the domain using DNS MX records
if not is_valid_domain(domain_part):
return False

addressVal(x)
# Validate if the domain supports internationalized domain names (IDNs)
if not validate_international_email(domain_part):
return False

return True

def is_valid_domain(domain):
"""
Checks if the domain has valid MX records.

Args:
domain (str): The domain to check.

Returns:
bool: True if the domain has valid MX records, False otherwise.
"""
try:
mx_records = dns.resolver.resolve(domain, 'MX')
return len(mx_records) > 0
except Exception:
return False

def validate_international_email(domain):
"""
Validates that the domain supports internationalized domain names (IDNs).

Args:
domain (str): The domain to validate.

Returns:
bool: True if the domain supports IDNs, False otherwise.
"""
try:
idna.encode(domain).decode('utf-8')
return True
except idna.IDNAError:
return False

if __name__ == "__main__":
email_input = input("Enter your email address: ")
if is_valid_email(email_input):
print("The email address is valid.")
else:
print("The email address is invalid.")
22 changes: 13 additions & 9 deletions Address Validator/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<!--Please do not remove this part-->
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99)
![Star Badge](https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=flat&color=BC4E99)
![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)

# Address Validator

## 🛠️ Description

This program validates email addresses through multiple checks, including syntax validation, and DNS MX record verification. It ensures that the email address contains an '@' symbol, checks for proper length constraints, and verifies that the domain is not unauthorized email service. The program also supports internationalized domain names, enhancing its usability for a global audience.

## 🛠️ Description
## ⚙️ Languages and Packages Used

This program checks if your email adress is valid by looking for an '@' symbol and a '.'
- **Language**: Python
- **Packages**:
- `dnspython` - For DNS resolution and MX record checks
- `idna` - To handle internationalized domain names

## ⚙️ Languages or Frameworks Used
Python
## 🌟 How to Run

## 🌟 How to run
Open the file AddressValidator.py file with the python IDE and hit run.
Open the `AddressValidator.py` file with a Python IDE and hit run.

## 🤖 Authors

## 🤖 Author
tommcgurn10
- **m-hassanqureshi** - Primary author of the renewed code
- **tommcgurn10** - Original author of the initial project
Binary file modified requirements.txt
Binary file not shown.