This gem does some tricks with Brazilian Telephone Numbers. It validates telephone numbers based on its area code, bands of operation and the rules defined by ANATEL. The implementation of the ninth digit in Brazil has also been taken into account when developing this gem.
API to illustrate its functionality: http://telefonia-br.herokuapp.com?tel=(YY)XXXXXX
Add this line to your application's Gemfile:
gem "telefonia_br"
And then execute:
$ bundle
Or install it yourself as:
$ gem install telefonia_br
require "telefonia_br"
tel = TelBr.new("(YY)XXXXXXXX")
tel.stripped # Return stripped telephone: YYXXXXXXXX
tel.formatted # Return formatted telephone: (YY) XXXX-XXXX
tel.ddd # Return the DDD: YY
tel.state # Return the state, such as "SP" for DDD 11 to 19
tel.region # Return the region, such as "São José dos Campos e Região." for DDD 12
tel.number # return the number: XXXXXXXX
tel.valid? # Check if a telephone number is valid
tel.error # Display the error if telephone number is invalid
If a telephone number is invalid you might get one of the following messages:
Invalid telephone
Invalid DDD
Invalid number
Number should have 8 digits
Number should have 9 digits
- Fork it
- Create your feature branch (
git checkout -b my-contribution
) - Commit your changes (
git commit -am "your message"
) - Push to the branch (
git push origin my-contribution
) - Create a new Pull Request