valvat-core

Core functionality extraction from the valvat gem - Validates european vat numbers.

Features

  • Simple syntax verification

valvat-core is tested and works with ruby MRI 1.9.3/2.0/2.1, jruby (in 1.9 mode) and rubinius 2.2

Installation

gem install valvat-core

Basic Usage

To verify the syntax of a vat number:

Valvat.new("DE345789003").valid?
=> true or false

It is also possible to bypass initializing a Valvat instance and check the syntax of a var number string directly with:

Valvat::Syntax.validate("DE345789003")
=> true or false

Utilities

To split a vat number into the country code and the remaining chars:

Valvat::Utils.split("ATU345789003")
=> ["AT", "U345789003"]

or

Valvat.new("ATU345789003").to_a
=> ["AT", "U345789003"]

Both methods always return an array. If it can not detect the country or the given country is located outside of europe it returns [nil, nil]. Please note that this does not strictly return the ISO country code: for greek vat numbers this returns the ISO language code 'EL' instead of the ISO country code 'GR'.

To extract the ISO country code of a given vat number:

Valvat.new("EL7345789003").iso_country_code
=> "GR"

To extract the vat country code (first two chars in every european vat number):

Valvat.new("EL7345789003").vat_country_code
=> "EL"

To normalize a vat number:

Valvat::Utils.normalize("atu345789003")
=> "ATU345789003"

This basically just removes trailing spaces and ensures all chars are uppercase.

valvat