scoopseven
scoopseven

Reputation: 1777

Validate Email Header in Python

I have a RegEx for validating email addresses, but I'm really looking to validate a whole From header. Any of these would be valid:

[email protected]
<[email protected]>
My Name <[email protected]>

Is there anything out there that would validate these as valid from headers? I'm going to look in the smtp library :)

Upvotes: 0

Views: 1136

Answers (2)

godswearhats
godswearhats

Reputation: 2255

Be aware that there are plenty of other valid cases of e-mail addresses beyond what you've posted.

See here for a recipe that may help. Also read this for a great discussion of parsing email addresses with a regex. There are any number of good regexes in there that will match the uses you're looking for, imho :-)

Upvotes: 1

scoopseven
scoopseven

Reputation: 1777

I couldn't get the posted response to work, so I've been working on this and finally got this one, which seems to work so far. I'm sure it'll miss/catch something, but it's working for now.

[a-zA-Z0-9+_\-\.\ ]*[ ]*<?[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+>?

Upvotes: 1

Related Questions