On 12/28/20 3:08 PM, Mats Wichmann wrote: > On 12/28/20 10:46 AM, Marco Sulla wrote: >> On Mon, 28 Dec 2020 at 17:37, Bischoop <bisch...@vimart.net> wrote: >>> >>> I'd like to check if there's "@" in a string and wondering if any >>> method >>> is better/safer than others. I was told on one occasion that I should >>> use is than ==, so how would be on this example. >>> >>> s = 't...@mail.is' >> >> You could do simply >> >> if "@" in s: >> >> but probably what you really want is a regular expression. >> > > Will add that Yes, you should always validate your inputs, but No, the > presence of an @ sign in a text string is not sufficient to know it's > a valid email address. Unfortunately validating that is hard. > Validating that it meets the SYNTAX of an email address isn't THAT hard, but there are a number of edge cases to worry about.
Validating that it is a working email address (presumably after verifying that it has a proper syntax) is much harder, and basically requires trying to send to the address, and to really confirm that it is good requires them to do something actively with a message you send them. And then nothing says the address will continue to be valid. -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list