Install via script/plugin
script/plugin install http://accounts4free.rubyforge.org/svn/plugins/validates_as_eu_vat_number
or use piston
piston import http://accounts4free.rubyforge.org/svn/plugins/validates_as_eu_vat_number
The plugin provides another validation helper validates_as_eu_vat_number which takes a set of attributes and an optional :with modifier that points to the attribute containing the country code, or a string containing the country code itself. If you don't use the :with modifier then the routine expects the country code to be the first two characters of the attribute itself, e.g:
class VatNumber < ActiveRecord::Base
:with => :country_code
In common with other validates plugins, this one takes the usual :if, :unless, :on, :message, :allow_nil and :allow_blank options provided by the underlying validation mechanism.
The plugin has rdoc documentation included. Run rake within the plugin directory to create it.
ValidatesAsEuVatNumber has an extensive test suite created using Rspec and a lot of Googling for VAT numbers. The easiest way to run the test suite is to do rake spec:plugins from the root directory of the Rails application containing the plugin (and the rspec and rspec_on_rails plugins as well obviously).
The plugin creates an EU module with a couple of constants in it.
EU::MEMBER_STATES_COUNTRY_CODES is an array containing the ISO code strings of all the EU member states.
EU::MEMBER_STATES_VAT_PICTURES is a hash indexed on the country code containing the Regular expression VAT pictures for every EU country .
And if you just want to check a VAT number to see if it is live, then use the online checker on Europa.
Let me know