/    Sign up×
Community /Pin to ProfileBookmark

RegExp – Validate E-mail

I know virtually no Regular Expressions, and I want to know if this about right for validating a given e-mail address?

[code]
var emailRE = new RegExp(/^(S)+@(S)+.(S)+$/);
alert(emailRE.test(formElement.email.value))
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@jeffmottDec 07.2002 — The best you're going to get.

[FONT=courier new]var emailRE = new RegExp(/^[^()<>@,;:".[]x00-x20x7f-xff]+(?:.[^()<>@,;:".[]x00-x20x7f-xff]+)*@[^()<>@,;:".[]x00-x20x7f-xff]+(?:.[^()<>@,;:".[]x00-x20x7f-xff]+)*$/);

alert(emailRE.test(formElement.email.value))[/FONT]

This regular expression was derived from [url=http://www.w3.org/Protocols/rfc822/#z8][RFC822] Standard for ARPA Internet Text Messages, Address Specification[/url]
Copy linkTweet thisAlerts:
@jeffmottDec 07.2002 — 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.
Copy linkTweet thisAlerts:
@jeffmottDec 07.2002 — Here's a possible alterative. With an address of the form local-part "@" domain, [url=http://www.w3.org/Protocols/rfc822/#z8][RFC822][/url] was used for the local-part and [url=http://www.ietf.org/rfc/rfc2396.txt][RFC2396]Uniform Resource Identifiers (URI): Generic Syntax[/url] for the domain.

[font=courier new]var emailRE = new RegExp(/^[^()<>@,;:".[]x00-x20x7f-xff]+(?:.[^()<>@,;:".[]x00-x20x7f-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]*)?$/);[/font]

...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?
Copy linkTweet thisAlerts:
@Rick_BullauthorDec 07.2002 — 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.
×

Success!

Help @Rick_Bull spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...