Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
email address input
#6
Doing the regex right is difficult. Much corner cases resulting in a longer regex.
This problem has been solved many times over and over.

One possible shortcut is the use of Pydantic.
It allows you to create models and those models are verified.


# py -m pip install pydantic[email]
from pydantic import BaseModel, EmailStr, ValidationError


class User(BaseModel):
    email: EmailStr



def test():
    while True:
        user_input = input("Please enter an email address: ")
        
        try:
            user = User(email=user_input)
        except ValidationError:
            print(f"[❌] Email '{user_input}' is invalid")
        else:
            print(f"[✓] Email '{user_input}' is valid")


if __name__ == "__main__":
    test()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
email address input - by jacksfrustration - Jun-26-2024, 05:03 AM
RE: email address input - by rodiongork - Jun-26-2024, 05:13 AM
RE: email address input - by jacksfrustration - Jun-26-2024, 05:17 AM
RE: email address input - by Pedroski55 - Jun-26-2024, 07:12 AM
RE: email address input - by menator01 - Jun-26-2024, 08:24 AM
RE: email address input - by DeaD_EyE - Jun-26-2024, 08:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in entering address of a file in input akbarza 0 784 Oct-18-2023, 08:16 AM
Last Post: akbarza
  Extracing unique email address from a folder of emails jehoshua 6 3,049 Oct-14-2020, 12:43 AM
Last Post: jehoshua
  Grabing email from a class with input from name Nickd12 2 1,923 Oct-13-2020, 06:22 PM
Last Post: Nickd12
  Slicing and printing two halfs of an email address (Udemy) Drone4four 5 3,004 Aug-26-2019, 09:01 AM
Last Post: wavic
  An email with inline jpg cannot be read by all email clients fpiraneo 4 4,243 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 6,085 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020