Jun-26-2024, 08:35 AM
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.
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!
All humans together. We don't need politicians!