class ActiveModel::Validations::SsnValidatorUSA

The Social Security number is a nine-digit number in the format “AAA-GG-SSSS”. The number is divided into three parts. AAA - is the first, GG - is the second and the SSSS is the third. More details: en.wikipedia.org/wiki/Social_Security_number

Public Class Methods

new(value) click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 24
def initialize(value)
  @value = value
  @first_group_num  = value[0..2].to_i
  @second_group_num = value[3..4].to_i
  @third_group_num  = value[5..8].to_i
end

Public Instance Methods

all_groups_integers?() click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 35
def all_groups_integers?
  begin
    !!Integer(@value)
  rescue ArgumentError, TypeError
    false
  end
end
first_group_valid?() click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 43
def first_group_valid?
  @first_group_num != 0 && @first_group_num != 666 && (@first_group_num < 900 || @first_group_num > 999)
end
second_group_valid?() click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 47
def second_group_valid?
  @second_group_num != 0
end
third_group_valid?() click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 51
def third_group_valid?
  @third_group_num != 0
end
valid?() click to toggle source
# File lib/active_validators/active_model/validations/ssn_validator.rb, line 31
def valid?
  all_groups_integers? && first_group_valid? && second_group_valid? && third_group_valid?
end