class ERegex::Internet
Public Class Methods
domain()
click to toggle source
# 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="")
click to toggle source
# 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
email()
click to toggle source
# 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)
click to toggle source
# File lib/easy-regex.rb, line 9 def email_custom(domain, length) /\A[\w+\-.]{1,#{length}}@#{domain}\z/i end
password()
click to toggle source
# 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="")
click to toggle source
# 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
url()
click to toggle source
# 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