Class: ActiveModel::Validations::IbanValidator

Inherits:
EachValidator
  • Object
show all
Includes:
EmptyBlankEachValidator
Defined in:
lib/active_model/validations/iban_validator.rb

Constant Summary collapse

USE_ORD =

use ord for ruby >= 1.9

''.respond_to?(:ord)

Instance Method Summary collapse

Methods included from EmptyBlankEachValidator

#validate_each

Instance Method Details

#valid?(iban) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/active_model/validations/iban_validator.rb', line 12

def valid?(iban)
  return false if iban.size < 3
  transpose((iban.slice(4, iban.size) + iban[0..3])).to_i % 97 == 1
rescue
  false
end