No commit activity in last 3 years
No release in over 3 years
Provides validators for spanish VAT numbers (NIF, CIF and NIE)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.2.0
 Project Readme

SpanishVatValidators Build StatusCode Climate

I've adapted the code from the ValidateSpanishVAT plugin from https://github.com/lleirborras/ValidateSpanishVAT to be distributed as a gem for ease of use with Rails >= 3.2.

Also added I18n support for error messages, which you can change by adding this to your locale yml:

es:
  errors:
    messages:
      not_valid_spanish_vat: El número de identificación fiscal no es válido
      not_valid_spanish_id: El NIF/NIE no es válido
      not_valid_nif: El NIF no es válido
      not_valid_cif: El CIF no es válido
      not_valid_nie: El NIE no es válido

Installation

Add this line to your application's Gemfile:

gem 'spanish_vat_validators'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spanish_vat_validators

Usage

Just use any of the following validators.

# A person id
class Spaniard < ActiveRecord::Base
  validates :dni, :valid_nif => true
end

# A company id
class Company < ActiveRecord::Base
  validates :cif, :valid_cif => true
end

# A foreigner id
class Alien < ActiveRecord::Base
  validates :nie, :valid_nie => true
end

# Any person id
class Person < ActiveRecord::Base
  validates :any_id, :valid_spanish_id => true
end

# Any kind of id is valid
class SpanishSubject < ActiveRecord::Base
  validates :nif, :valid_spanish_vat => true
end

You can override the error message using the message option.

class Person < ActiveRecord::Base
  validates :dni, valid_nif: { message: 'invalid' }
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request