Skip to content

Instantly share code, notes, and snippets.

@bernEsp
Created November 5, 2014 07:32
Show Gist options
  • Save bernEsp/baad9e63689f64a1ecb2 to your computer and use it in GitHub Desktop.
Save bernEsp/baad9e63689f64a1ecb2 to your computer and use it in GitHub Desktop.
regex to validate email with names and delimiter
Regexp.new('\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(\z|\s<\w+(?:>\z|\s\w+>\z))', true) |~
Regexp.new('(?:\A|,{1})(?:<{0,1})([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{0,1})', true) |~
Regexp.new('(?:\s<|w+\s)([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>|,{0,1}\z)', true) |~
Regexp.new('(?:^([^<@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})|^(?:\w+\s)+<{1}([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{1}$))', true)
Regexp.new('(?:^([^<@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z|^(?:\w+\s)+<{1}([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{1}$))', true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment