- Tiago Machado (tiago@synapses.com.br)
- João Lucas (joaolucas@synapses.com.br)
Based on Brazilian Rails (https://github.com/tapajos/brazilian-rails)
Include "synapses-validators" in yor gemfile.
gem 'synapses-validators'
Go to your models, and set your validators.
validates :cpf, :presence => true, :uniqueness => true, :cpf => true, :if => :is_person_br?
Or
act_as_cpf :cpf
validates :cnpj, :presence => true, :uniqueness => true, :cnpj => true, :if => :is_business_br?
Or
act_as_cnpj :cpf
validates :email,
:presence => true,
:uniqueness => true,
:length => {:within => 5..50},
:email_format => true
The error messages is localized. So, you must have this lines in your locale files:
activerecord:
errors:
messages:
invalid: inválido
not_formatted: não está no formato correto
- Implement tests.
Synapses Validators is licensed for use under the terms of the MIT License.