Skip to content

Instantly share code, notes, and snippets.

@sstelfox
Last active August 29, 2015 14:03
Show Gist options
  • Save sstelfox/bea3379576c0814f79ff to your computer and use it in GitHub Desktop.
Save sstelfox/bea3379576c0814f79ff to your computer and use it in GitHub Desktop.
Email Validation Regex
# According to RFC1123 the following characters may appear in a host name:
#
# * A to Z ; upper case characters
# * a to z ; lower case characters
# * 0 to 9 ; numeric characters 0 to 9
# * - ; dash
#
# Additionally the host name must obey the following rules:
#
# * A host name (label) can start or end with a letter or a number
# * A host name (label) MUST NOT start or end with a '-' (dash)
# * A host name (label) MUST NOT consist of all numeric values
# * A host name (label) can be up to 63 characters
#
# Everything prior to the @ sign before the host name in an email address
# should be allowed (there are no restrictions except those imposed by the
# receiving mail server).
email_regex1 = /\A.*@(?=.{1,255}$)[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?)*\.?\z/i
hostname_label_regex = /\A(?![0-9]+$)(?!-)[a-z0-9-]{,63}(?<!-)\z/i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment