[relaxng-user] rfc2822 compliant email pattern?

David Tolpin dvd at davidashen.net
Fri Jan 16 23:35:31 ICT 2004


> Is it possible to write a pattern for an email address please?
> 
> fred at example.com
> fred.baker at example.org.uk
> 
> tia.  DaveP

Dave,

if you need a regular expression for addr-spec, then it is

start=element addr-spec { 
  xsd:token {
  pattern="""([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+)*|"[^"\\]*")@([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+)*|\[[^\[\]\\]*\])"""
  }
}

Works for both normal addresses and forms like

"David Tolpin"@[Obscure Place]

The expression above is slightly more allowing than required, but should be appropriate
for the majority of cases.

David


More information about the relaxng-user mailing list