开发者

Validate VAT number offline

I'm writing a small app with different inputs from a file (like countrycode, vat number etc) and I have to validate that the vat numbers are in the correct format.

I've tried this one: http://www.codeproject.com/KB/webservices/VATchecker.aspx - and it 开发者_如何转开发works.. but, and yes, there's always a but :-), I have to check anywhere from 100 - 500 vat numbers and it's just too slow for that. Besides, I'm not sure they appreciate me hammering their site like that.

Does anyone know of an offline vat-validater I can build into my C# program?


Based on @Uwe Keim's (outdated) Answer i made the regex'es for 2014 with these rules: http://www.bzst.de/DE/Steuern_International/USt_Identifikationsnummer/Merkblaetter/Aufbau_USt_IdNr.html?nn=23440

AT ^ATU[A-Z0-9]{8,8}$ 
BE ^BE[0-9]{10,10}$ 
BG ^BG[0-9]{9,9}$|^BG[0-9]{10,10}$
CY ^CY[0-9]{8,8}[A-Z]{1,1}$ 
CZ ^CZ[0-9]{8,10}$
DE ^DE[0-9]{9,9}$
DK ^DK[0-9]{8,8}$
EE ^EE[0-9]{9,9}$
ES ^ES[A-Z0-9]{1,1}[0-9]{7,7}[A-Z0-9]{1,1}$ 
FI ^FI[0-9]{8,8}$ 
FR ^FR[A-Z0-9]{2,2}[0-9]{9,9}$ 
GB ^GB[0-9]{9,9}$|^GB[0-9]{12,12}$|^GBGD[0-9]{3,3}$|^GBHA[0-9]{3,3}$ 
HU ^HU[0-9]{8,8}$ 
IE ^IE[0-9]{1,1}[A-Z0-9]{1,1}[0-9]{5,5}[A-Z]{1,1}$|^IE[0-9]{7,7}[A-W]{1,1}[A-I]{1,1}$ 
IT ^IT[0-9]{11,11}$ 
LT ^LT[0-9]{9,9}$|^LT[0-9]{12,12}$
LU ^LU[0-9]{8,8}$ 
LV ^LV[0-9]{11,11}$ 
MT ^MT[0-9]{8,8}$ 
NL ^NL[A-Z0-9]{9,9}B[A-Z0-9]{2,2}$ 
PL ^PL[0-9]{10,10}$   
PT ^PT[0-9]{9,9}$
SE ^SE[0-9]{10,10}01$
SI ^SI[0-9]{8,8}$
SK ^SK[0-9]{10,10}$
RO ^RO[1-9]{1,1}[0-9]{1,9}$
EL ^EL[0-9]{9,9}$ 
HR ^HR[0-9]{11,11}$ 

Someone may need it.


In our online shops, I'm doing it similar to the solution in the Code Project article.

Before submitting it to the web services I do a small regular expression sanity check to filter out "syntactially" wrong VAT IDs and therefore reduce the number of SOAP calls I have to perform.

This is an excerpt from the table I'm using to store the regular expressions, maybe this helps you, if you plan something similar:

Code2    VatIDRegex
----------------------------------------------------------
at       ^ATU[A-Z0-9]{8,8}$
be       ^BE[0-9]{9,9}$
cy       ^CY[0-9]{9,9}$
cz       ^CZ[0-9]{8,10}$
de       ^DE[0-9]{9,9}$
dk       ^DK[0-9]{8,8}$
ee       ^EE[0-9]{9,9}$
es       ^ES[A-Z0-9]{1,1}[0-9]{7,7}[A-Z0-9]{1,1}$
fi       ^FI[0-9]{8,8}$
fr       ^FR[A-Z0-9]{2,2}[0-9]{9,9}$
gb       ^GB[0-9]{9,9}$|^GB[0-9]{12,12}$|^GBGD[0-9]{3,3}$
hu       ^HU[0-9]{8,8}$
ie       ^IE[A-Z0-9]{8,8}$
it       ^IT[0-9]{11,11}$
lt       ^LT[0-9]{9,9}$|^LT[0-9]{12,12}$
lu       ^LU[0-9]{8,8}$
lv       ^LV[0-9]{11,11}$
mt       ^MT[0-9]{8,8}$
nl       ^NL[A-Z0-9]{9,9}B[A-Z0-9]{2,2}$
pl       ^PL[0-9]{10,10}$
pt       ^PT[0-9]{9,9}$
se       ^SE[0-9]{12,12}$
si       ^SI[0-9]{8,8}$
sk       ^SK[0-9]{10,10}$


You can try this http://code.google.com/p/vat-validation/ It's still work in progress but has the code for almost all the EU countries.


If you look at this site they do specify the structure of the VAT numbers for each of the member states. Possibly you could do a check for your numbers being in the correct structure first which might avoid having to do some of the requests.

Other than that, I think you will have to use this webservice to validate the numbers. The webservice does not link to a single database but rather connect to each state's database to verify the number, so there's no single database that you could download (maybe some states will have downloads of all valid VAT numbers that you could download, but I doubt it and you'd have to make sure that it's kept up to date etc).

As Steven suggests in his comment though, you might be able to speed it up by doing multiple requests at the same time. I wouldn't have thought that this would be a problem but you could always email the address mentioned in Q16 on that page and ask them if that is ok.


   if (vatNo.Length == 9)
            {
                int calcValue = 0;
                int index = 0;
                int checkDigit = Convert.ToInt32(vatNo.Substring(7, 2));

                for (int ordinate = 8; ordinate > 1; ordinate--)
                {
                    calcValue += Convert.ToInt32((vatNo.Substring(index, 1))) * ordinate;
                    index++;
                }
                while (calcValue > 0)
                {
                    calcValue -= 97;
                }
                if ((calcValue * -1) != checkDigit)
                {
                    Error
                }

            }


If it's an option for you, you may use js-lib (my as well):

https://github.com/se-panfilov/jsvat

(jsvat check's VAT number twice - with regexp and with math calculation)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜