Advertisement
Python253

is_valid_email

Mar 3rd, 2024 (edited)
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: is_valid_email.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. Valid Email Checker Script
  8.  
  9. This script prompts the user to enter an email address and checks whether
  10. it is in a valid email format. It utilizes a function, valid_email, to
  11. perform the email validation.
  12.  
  13. Requirements:
  14. - Python 3
  15.  
  16. Usage:
  17. 1. Run the script.
  18. 2. Enter an email address when prompted.
  19. 3. The script will display whether the entered email address is valid or not.
  20. """
  21.  
  22. import re
  23.  
  24. def valid_email(email):
  25.     """Check for a valid email address.
  26.  
  27.    Args:
  28.        email (str): Email.
  29.  
  30.    Returns:
  31.        bool: True if in valid email format, False otherwise.
  32.  
  33.    """
  34.     return bool(re.match('^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$', email))
  35.  
  36. def main():
  37.     # Get user input for email address
  38.     user_email = input("Enter an email address: ")
  39.  
  40.     # Check if the email is valid
  41.     if valid_email(user_email):
  42.         print("The entered email address is Valid.")
  43.     else:
  44.         print("The entered email address is Not Valid.")
  45.  
  46. if __name__ == "__main__":
  47.     main()
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement