On Thu, Feb 09, 2012 at 01:15:52PM +0530, Ram wrote: > I am trying to validate email ids of subscribers coming to my site > Is there a standard regular expression for email id syntax that > confirms to rfc822. > > I want to avoid junk entries from entering my database. > > Postfix already checks this syntax in RCPT-TO , but is this regex > available already
Often it is a mistake to attempt to parse complex grammars with mere regular expressions, some constructs are not handled by regexps in full generality. https://tools.ietf.org/html/rfc5322#section-3.4.1 In this case you need to support: addr-spec = local-part "@" domain local-part = dot-atom / quoted-string / obs-local-part domain = dot-atom / domain-literal / obs-domain domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] dtext = %d33-90 / ; Printable US-ASCII %d94-126 / ; characters not including obs-dtext ; "[", "]", or "\" So, ignoring obsolete forms, you need a regexp for a valid quoted-string, and a valid dot-atom. Then: (<quoted-string-regexp>|<dot-atom-regexp>)@<dot-atom-regexp> One may be more strict about the domain part, and check it is a valid DNS domain, and has MX records or A (or AAAA) records. The dot-atom and quoted-string syntax is defined in other sections of RFCs 5322/5321.