-1

I just wanted to ask if your are writing a program in python and ask the user to input an email address, how can you validate it and make sure it is true?

address= input ("Please ente your postal address: ")

And then I would also need to repeat the question if the address is not true.

Tugrul Ates
  • 9,451
  • 2
  • 33
  • 59
Tanisha
  • 11
  • 1
  • 2
    You can't, really, without sending them an email and waiting for them to somehow verify that they received it. Also that's a completely different thing to a postal address. – jonrsharpe Dec 10 '17 at 18:58
  • Does this answer your question? [How to check for valid email address?](https://stackoverflow.com/questions/8022530/how-to-check-for-valid-email-address) – Tugrul Ates Aug 19 '23 at 06:07

2 Answers2

1

Beyond the basic format validation, this is usually done by sending an email to the provided address with a secret code and asking the user to enter the secret code in your program. For web apps the secret code is usually embedded in a link so the user does not have to type the code.

This doesn't exactly warranties that the email address "is true" because the email address can be temporary, but that's as close as you can get without hiring a private detective that looks into the private life of your user...

jacmkno
  • 1,189
  • 11
  • 25
1

To check if the email address's domain name is valid (i.e., the part after @), you could use nslookup on *nix systems, call it in a Python subprocess.

You could also check the string you get against the official email Regex.

Put together; those two methods will tell you if the email is syntactically correct and with a valid domain. Which is often not enough...

To do full email validation, you're forced to use an external API that offers this service. A lot of email verifiers will pop up if you google for it.

Of course, the most robust way to go, and the only one that guarantees the email is valid AND is owned by the user, is to send a verification email with a link inside for your user to verify its email.

Pierre Hay
  • 21
  • 4