On 28Dec2020 13:08, Mats Wichmann <m...@wichmann.us> 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.
Others have pointed out: '@' in s >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 is a functional email address is hard, involves delivering email and then finding out if it was delivered. A proper syntax check requires parsing an RFC5322 address grammar: https://tools.ietf.org/rfcmarkup/5322#section-3.4 Fortunately, Python ships with one of those in the email.utils module. The parseaddr() function will parse a single address, and getaddresses() will parse a list of addresses such as might be in a To: header line. They work well - I've been filing my email based on these for years - MANY thousands of messages. Cheers, Cameron Simpson <c...@cskk.id.au> -- https://mail.python.org/mailman/listinfo/python-list