Click to See Complete Forum and Search --> : RegExp - Validate E-mail
Rick Bull
12-06-2002, 07:26 AM
I know virtually no Regular Expressions, and I want to know if this about right for validating a given e-mail address?
var emailRE = new RegExp(/^(\S)+\@(\S)+\.(\S)+$/);
alert(emailRE.test(formElement.email.value))
jeffmott
12-06-2002, 06:32 PM
The best you're going to get.
var emailRE = new RegExp(/^[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+(?:\.[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+)*\@[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+(?:\.[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+)*$/);
alert(emailRE.test(formElement.email.value))
This regular expression was derived from [RFC822] Standard for ARPA Internet Text Messages, Address Specification (http://www.w3.org/Protocols/rfc822/#z8)
jeffmott
12-06-2002, 07:17 PM
I was curious if anyone knew if RFC822 is outdated and been replaced by another recommendation. One of my concerns with it is the domain is allowed to contain symbol characters.
jeffmott
12-06-2002, 07:42 PM
Here's a possible alterative. With an address of the form local-part "@" domain, [RFC822] (http://www.w3.org/Protocols/rfc822/#z8) was used for the local-part and [RFC2396]Uniform Resource Identifiers (URI): Generic Syntax (http://www.ietf.org/rfc/rfc2396.txt) for the domain.
var emailRE = new RegExp(/^[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+(?:\.[^()<>@,;:\\".[\]\x00-\x20\x7f-\xff]+)*\@(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]\.)*(?:[a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?|[0-9]+.[0-9]+.[0-9]+.[0-9]+)(?::[0-9]*)?$/);
...though I've never known the local-part to contain symbols either (!#$%^&*{}'?/) grrr
Which document specifically and accurately describes the allowed syntax of an e-mail address?
Rick Bull
12-07-2002, 06:18 AM
Thanks for the input guys.
I'm not sure about what characters an e-mail can contain Jeff, maybe I'll see if I can find something online somewhere.