Skip to main content

Simple email and phone number validation library

Project description

email-phone-validator

A simple, production-ready Python package for validating email addresses and phone numbers.

Features

  • Email Validation: Validate email addresses using regex patterns
  • Phone Validation: Validate phone numbers using the phonenumbers library
  • Country Support: Default country is India (IN), but supports any country code
  • Clean API: Simple and intuitive functions
  • Well Tested: Comprehensive unit tests included
  • Production Ready: Follows Python packaging best practices

Installation

pip install email-phone-validator

Quick Start

from email_phone_validator import validate_email, validate_phone

# Validate email
print(validate_email("test@gmail.com"))      # True
print(validate_email("invalid.email"))       # False

# Validate phone (default country: India)
print(validate_phone("9876543210"))          # True
print(validate_phone("+919876543210"))       # True
print(validate_phone("12345"))               # False

# Validate phone for other countries
print(validate_phone("+12025551234", "US"))  # True
print(validate_phone("2025551234", "US"))    # True

Usage Examples

Email Validation

from email_phone_validator import validate_email

# Valid emails
validate_email("user@example.com")           # True
validate_email("john.doe@company.co.uk")     # True
validate_email("user+tag@example.com")       # True

# Invalid emails
validate_email("invalid.email")              # False
validate_email("@example.com")               # False
validate_email("user@")                      # False

Phone Validation

from email_phone_validator import validate_phone

# Indian phone numbers (default country)
validate_phone("9876543210")                 # True
validate_phone("+919876543210")              # True
validate_phone("919876543210")               # True

# US phone numbers
validate_phone("+12025551234", "US")         # True
validate_phone("2025551234", "US")           # True

# UK phone numbers
validate_phone("+447911123456", "GB")        # True
validate_phone("07911123456", "GB")          # True

# Invalid phone numbers
validate_phone("12345", "IN")                # False
validate_phone("abc1234567", "IN")           # False

Combined Usage

from email_phone_validator import validate_email, validate_phone

def validate_user_data(email, phone, country="IN"):
    """Validate user email and phone number."""
    email_valid = validate_email(email)
    phone_valid = validate_phone(phone, country)
    
    if email_valid and phone_valid:
        return True, "All validations passed"
    else:
        errors = []
        if not email_valid:
            errors.append("Invalid email address")
        if not phone_valid:
            errors.append("Invalid phone number")
        return False, ", ".join(errors)

# Example usage
is_valid, message = validate_user_data(
    email="user@example.com",
    phone="9876543210",
    country="IN"
)
print(f"Validation: {is_valid}, Message: {message}")

API Reference

validate_email(email: str) -> bool

Validates an email address using regex patterns.

Parameters:

  • email (str): The email address to validate

Returns:

  • bool: True if the email is valid, False otherwise

validate_phone(phone: str, country: str = "IN") -> bool

Validates a phone number for a given country using the phonenumbers library.

Parameters:

  • phone (str): The phone number to validate (can be with or without country code)
  • country (str): ISO country code (default: "IN" for India)
    • Examples: "US", "GB", "IN", "AU", "CA", etc.

Returns:

  • bool: True if the phone number is valid, False otherwise

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/yourusername/email-phone-validator.git
cd email-phone-validator

# Install in development mode
pip install -e .

# Install development dependencies
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=email_phone_validator

# Run specific test file
pytest tests/test_email.py
pytest tests/test_phone.py

Building the Package

# Install build tools
pip install build twine

# Build the package
python -m build

# This creates:
# - dist/email_phone_validator-0.1.0.tar.gz
# - dist/email_phone_validator-0.1.0-py3-none-any.whl

Publishing to PyPI

  1. Create a PyPI account: https://pypi.org/account/register/

  2. Upload the package:

    twine upload dist/*
    
  3. Test the installation:

    pip install email-phone-validator
    

Requirements

  • Python >= 3.7
  • phonenumbers >= 8.13.0

Supported Countries

The phone validation supports all countries supported by the phonenumbers library, including but not limited to:

  • India (IN) - Default
  • United States (US)
  • United Kingdom (GB)
  • Australia (AU)
  • Canada (CA)
  • And many more...

For a complete list, refer to the phonenumbers library documentation.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Your Name - youremail@gmail.com

Acknowledgments

  • Uses phonenumbers library for phone validation
  • Built with ❤️ for the Python community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

phone_and_mail_verifier-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phone_and_mail_verifier-0.1.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file phone_and_mail_verifier-0.1.1.tar.gz.

File metadata

  • Download URL: phone_and_mail_verifier-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for phone_and_mail_verifier-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0b12c50bd868c0a3387096ae62988b92d86db3f15cdc5e8622a63a29738267cd
MD5 09da024cefd9ec6589abcff90de4f53e
BLAKE2b-256 a2dd07b2201ab8c302eeb782f956fbe7f070b5cf9b34181bddaa7cca1352e0d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for phone_and_mail_verifier-0.1.1.tar.gz:

Publisher: workflow.yml on Skywebsite/phone-and-mail-verifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file phone_and_mail_verifier-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for phone_and_mail_verifier-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d98376ccbf2bc5ce60bb2b366ac60e1f4d017d8a2d416f45ba58128a1d810e56
MD5 6ed9c751ea647a4014c35dd3a005e698
BLAKE2b-256 f8649f140678a3f8942a28a43c5733c0079ae2865c2c7e25d41d1b2ed2e013b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for phone_and_mail_verifier-0.1.1-py3-none-any.whl:

Publisher: workflow.yml on Skywebsite/phone-and-mail-verifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page