Module: Authlogic::Regex
- Defined in:
- lib/authlogic/regex.rb
Overview
Class Method Summary collapse
-
.email ⇒ Object
A general email regular expression.
-
.email_nonascii ⇒ Object
A draft regular expression for internationalized email addresses.
-
.login ⇒ Object
A simple regular expression that only allows for letters, numbers, spaces, and .-_@+.
Class Method Details
.email ⇒ Object
A general email regular expression. It allows top level domains (TLD) to be from 2 - 24 in length. The decisions behind this regular expression were made by analyzing the list of top-level domains maintained by IANA and by reading this website: www.regular-expressions.info/email.html, which is an excellent resource for regular expressions.
13 14 15 16 17 18 19 20 |
# File 'lib/authlogic/regex.rb', line 13 def self.email @email_regex ||= begin email_name_regex = '[A-Z0-9_\.&%\+\-\']+' domain_head_regex = '(?:[A-Z0-9\-]+\.)+' domain_tld_regex = '(?:[A-Z]{2,25})' /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i end end |
.email_nonascii ⇒ Object
A draft regular expression for internationalized email addresses. Given that the standard may be in flux, this simply emulates @email_regex but rather than allowing specific characters for each part, it instead disallows the complement set of characters:
-
email_name_regex disallows: @[]^ !“#$()*,/:;<=>?‘{|}~\ and control characters
-
domain_head_regex disallows: _%+ and all characters in email_name_regex
-
domain_tld_regex disallows: 0123456789- and all characters in domain_head_regex
en.wikipedia.org/wiki/Email_address#Internationalization tools.ietf.org/html/rfc6530 www.unicode.org/faq/idn.html ruby-doc.org/core-2.1.5/Regexp.html#class-Regexp-label-Character+Classes en.wikipedia.org/wiki/Unicode_character_property#General_Category
33 34 35 36 37 38 39 40 |
# File 'lib/authlogic/regex.rb', line 33 def self.email_nonascii @email_nonascii_regex ||= begin email_name_regex = '[^[:cntrl:][@\[\]\^ \!\"#$\(\)*,/:;<=>\?`{|}~\\\]]+' domain_head_regex = '(?:[^[:cntrl:][@\[\]\^ \!\"#$&\(\)*,/:;<=>\?`{|}~\\\_\.%\+\']]+\.)+' domain_tld_regex = '(?:[^[:cntrl:][@\[\]\^ \!\"#$&\(\)*,/:;<=>\?`{|}~\\\_\.%\+\-\'0-9]]{2,25})' /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/ end end |
.login ⇒ Object
A simple regular expression that only allows for letters, numbers, spaces, and .-_@+. Just a standard login / username regular expression.
44 45 46 |
# File 'lib/authlogic/regex.rb', line 44 def self.login /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/ end |