class SocialSecurityNumber::Us

SocialSecurityNumber::Us validates U.S. (America) Social Security number (SSN) and Individual Taxpayer Identification Number (ITIN), Employer Identification Number (EIN) en.wikipedia.org/wiki/National_identification_number#United_States www.ssa.gov/employer/verifySSN.htm en.wikipedia.org/wiki/Social_Security_number en.wikipedia.org/wiki/Individual_Taxpayer_Identification_Number

Constants

EIN_REGEXP
ITIN_REGEXP
SSN_REGEXP

Public Instance Methods

validate() click to toggle source
# File lib/social_security_number/country/us.rb, line 9
def validate
  @error = if !validate_formats
             'bad number format'
           end
end

Private Instance Methods

validate_ein() click to toggle source
# File lib/social_security_number/country/us.rb, line 47
def validate_ein
  matches = @civil_number.match(self.class::EIN_REGEXP) || (return nil)
  matches[:area] =~ /^(0[1-6]||1[0-6]|2[0-7]|[35]\d|[468][0-8]|7[1-7]|9[0-58-9])$/
end
validate_formats() click to toggle source
# File lib/social_security_number/country/us.rb, line 21
def validate_formats
  (check_by_regexp(SSN_REGEXP) && validate_ssn) ||
  (check_by_regexp(ITIN_REGEXP) && validate_itin) ||
  (check_by_regexp(EIN_REGEXP) && validate_ein)
end
validate_itin() click to toggle source
# File lib/social_security_number/country/us.rb, line 38
def validate_itin
  matches = @civil_number.match(self.class::ITIN_REGEXP) || (return nil)
  if [70..88].include?(matches[:group].to_i) || matches[:area][0] != '9'
    return false
  else
    return true
  end
end
validate_ssn() click to toggle source
# File lib/social_security_number/country/us.rb, line 27
def validate_ssn
  matches = @civil_number.match(self.class::SSN_REGEXP) || (return nil)

  if matches[:area] == '000' || matches[:area] == '666' || matches[:group] == '00' ||
     matches[:invidual] == '0000' || matches[:area][0] == '9'
    return false
  else
    return true
  end
end