regex for email validation

I have written the regex below for a really simple email validation. I plan to send a confirmation link.

/.*@[a-z0-9.-]*/i

I would, however, like to enhance it from the current state because a string like this does not yield the desired result:

test ,my.name+test@gmail-something.co.uk, test

The "test ," portion is undesirably included in the match. I experimented with word boundaries unsuccessfully.

  • How should I modify?
  • Even though I've kept this simple, are there any valid email formats it would exclude?
  • THANKS!


    Instead of . try matching every character except s (whitespace):

    /[^s]*@[a-z0-9.-]*/i
    

    It's a lot more complicated !!! See Mail::RFC822::Address and be scared...very scared.


    Don't use regular expressions to validate e-mail addresses

    Instead, from mail.python.org/pipermail/python-list1 written by Ben Finney.

    The best advice I've seen when people ask "How do I validate whether an email address is valid?" was "Try sending mail to it".

    It's both Pythonic, and truly the best way. If you actually want to confirm, don't try to validate it statically; use the email address, and check the result. Send an email to that address, and don't use it any further unless you get a reply saying "yes, this is the right address to use" from the recipient.

    The sending system's mail transport agent, not regular expressions, determines which part is the domain to send the mail to.

    The domain name system, not regular expressions, determines what domains are valid, and what host should receive mail for that domain.

    Most especially, the receiving mail system, not regular expressions, determines what local-parts are valid.

    1This is original link before it went dead

    链接地址: http://www.djcxy.com/p/16560.html

    上一篇: 发送正则表达式

    下一篇: 正则表达式用于电子邮件验证