Class: ERegex::Internet

Inherits:
Object
  • Object
show all
Defined in:
lib/easy-regex.rb

Class Method Summary collapse

Class Method Details

.domainObject



22
23
24
# File 'lib/easy-regex.rb', line 22

def domain
  /[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
end

.domain_custom(length, end_with = "") ⇒ Object



26
27
28
29
# File 'lib/easy-regex.rb', line 26

def domain_custom(length, end_with="")
  return /^[a-z\d\-]{0,#{length}}(\.[a-z\d\-]{0,#{length}})*\.[a-z]+\z/ if end_with.length == 0
  /[a-z\d\-]{0,#{length}}(\.[a-z\d\-]{0,#{length}})*\.#{end_with}\z/
end

.emailObject



4
5
6
7
# File 'lib/easy-regex.rb', line 4

def email
  # Regex to validate an email -> from Michael Hartl Rails book 
  /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
end

.email_custom(domain, length) ⇒ Object



9
10
11
# File 'lib/easy-regex.rb', line 9

def email_custom(domain, length)
   /\A[\w+\-.]{1,#{length}}@#{domain}\z/i
end

.passwordObject



13
14
15
16
# File 'lib/easy-regex.rb', line 13

def password
  # Regex if a string contains at least a lowercase letter, a uppercase, a digit, a scpecial char and +8 chars
  /^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,}$/
end

.password_custom(length, start_with = "", end_with = "") ⇒ Object



18
19
20
# File 'lib/easy-regex.rb', line 18

def password_custom(length, start_with="", end_with="")
  /^#{start_with}(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{#{length},}#{end_with}$/
end

.urlObject



31
32
33
# File 'lib/easy-regex.rb', line 31

def url
  /^((http|https):\/\/)(([a-z0-9-\.]*)\.)?([a-z0-9-]+)\.([a-z]{2,5})(:[0-9]{1,5})?(\/)?$/ix
end