Class: OmgValidator::Validators::StrongPasswordValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/omg_validator/validators/strong_password_validator.rb

Overview

Checks whether password input is a strong password Must contain a least one number, one lower case letter and one upper case letter

validates :password, strong_password: true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/omg_validator/validators/strong_password_validator.rb', line 8

def validate_each(record, attribute, value)
  return nil if value.nil?
  reg = '/^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/'
  unless reg.match(value)
    record.errors[attribute] = "must contain at least a number, a lower case letter, and a upper case letter"
  end
end