Skip to main content
Reverted the improvement made to my simple pattern. Yes, it can be improved, but that's not the point of my answer. It's intentionally simple and overbroad.
Source Link
Andy Lester
  • 94.2k
  • 16
  • 106
  • 162

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^[^\s@]+@[^\s@]+\^\S+@\S+\.[^\s@]+$\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playinggetting common simple errors.

There are any number of changes that can be made to that regex (and some are in the 90/10 rulecomments for this answer), but it's simple, and easy to understand, and is a fine first attempt.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of getting common simple errors.

There are any number of changes that can be made to that regex (and some are in the comments for this answer), but it's simple, and easy to understand, and is a fine first attempt.

Slightly longer version, yet still simple, prevents e.g. a@@b.c
Source Link
Łukasz K
  • 572
  • 6
  • 11

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^\S+@\S+\^[^\s@]+@[^\s@]+\.\S+$[^\s@]+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

Corrected to make sense in context, and support the OP's comment 10/16/12. Random noise added to meet 6 character rule.
Source Link
WattsInABox
  • 4.6k
  • 2
  • 37
  • 43

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like 'bob @ aol.com'bob @ aol.com (spaces in emails) or 'steve'steve (no domain at all) or 'mary@aolcom'mary@aolcom (no period before .com), I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like 'bob @ aol.com' or 'steve' or 'mary@aolcom', I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

It all depends on how accurate you want to be. For my purposes, where I'm just trying to keep out things like bob @ aol.com (spaces in emails) or steve (no domain at all) or mary@aolcom (no period before .com), I use

/^\S+@\S+\.\S+$/

Sure, it will match things that aren't valid email addresses, but it's a matter of playing the 90/10 rule.

Corrected to make sense in context, and support the OP's comment 10/16/12. Random noise added to meet 6 character rule.
Source Link
Loading
Added dot as dot is mandatory for email address before domain address.
Source Link
Pupil
  • 24k
  • 6
  • 49
  • 71
Loading
Post Made Community Wiki
Source Link
Andy Lester
  • 94.2k
  • 16
  • 106
  • 162
Loading