'Russia VAT Number validation
Does anyone have code to validate for validating Russian TAX Registration number (VAT). C# code will be great, but if someone have some other language it will be helpful also.
Format (Russian VAT number = "Tax Identification Number" = "Идентификационный номер налогоплательщика"):
10 digits (legal personality) or 12 digits (human persons), fist two digits are region of birth or company registration (for foreign companies, two digits after leading 99) MOD 11-10
second two- inspection (before the year 2004, it changed, now stays).
for legal personality use the changeable second code (KPP), usually first 4 digits are the same (99-region rule does not apply), usually and default XXXX01001.
KPP is also the counter (last 3 digts)
The number of KPP's is limited to number of tax inspections in regions other than 77 and 50 (one and only for each) plus one code for the largest companies.
source: http://en.wikipedia.org/wiki/VAT_identification_number#VAT_numbers_of_non-EU_countries
Solution 1:[1]
Here is a C# program that will validate the Russian personal and company VAT numbers. Please consider that further input validation should be done (verifying that the passed VAT numbers contain only digits, that they have the required length and so on):
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
class VatNumber
{
private int[] _numericVatNumber;
public int[] NumericVatNumber { get { return _numericVatNumber; } }
public VatNumber(string vatNumber)
{
_numericVatNumber = vatNumber.ToCharArray().Select(i => int.Parse(i.ToString())).ToArray();
}
public virtual bool IsValid(){return false;}
}
class PersonalVatNumber : VatNumber
{
public override bool IsValid()
{
var n10 = ((2 * NumericVatNumber[0] +
4 * NumericVatNumber[1] +
10 * NumericVatNumber[2] +
3 * NumericVatNumber[3] +
5 * NumericVatNumber[4] +
9 * NumericVatNumber[5] +
4 * NumericVatNumber[6] +
6 * NumericVatNumber[7] +
8 * NumericVatNumber[8]) % 11) % 10;
if (n10 == NumericVatNumber.Last())
return true;
return false;
}
public PersonalVatNumber(string vatNumber)
: base(vatNumber)
{
}
}
class CompanyVatNumber : VatNumber
{
public override bool IsValid()
{
var n11 = ((7 * NumericVatNumber[0] +
2 * NumericVatNumber[1] +
4 * NumericVatNumber[2] +
10 * NumericVatNumber[3] +
3 * NumericVatNumber[4] +
5 * NumericVatNumber[5] +
9 * NumericVatNumber[6] +
4 * NumericVatNumber[7] +
6 * NumericVatNumber[8] +
8 * NumericVatNumber[9]
) % 11) % 10;
if (n11 != NumericVatNumber[10])
return false;
var n12 = ((3 * NumericVatNumber[0] +
7 * NumericVatNumber[1] +
2 * NumericVatNumber[2] +
4 * NumericVatNumber[3] +
10 * NumericVatNumber[4] +
3 * NumericVatNumber[5] +
5 * NumericVatNumber[6] +
9 * NumericVatNumber[7] +
4 * NumericVatNumber[8] +
6 * NumericVatNumber[9] +
8 * NumericVatNumber[10]
) % 11) % 10;
if (n12 == NumericVatNumber.Last())
return true;
return false;
}
public CompanyVatNumber(string vatNumber)
: base(vatNumber)
{
}
}
static void Main(string[] args)
{
var companyVat = new CompanyVatNumber("123456789047");
Console.WriteLine(companyVat.IsValid());
var personalVat = new PersonalVatNumber("1234567894");
Console.WriteLine(personalVat.IsValid());
}
}
}
Solution 2:[2]
If it's an option for you, you may use js lib (my as well):
https://github.com/se-panfilov/jsvat
It support eu (and russians too) VAT numbers.
(jsvat check's VAT number twice - with regexp and with math calculation)
Solution 3:[3]
You can check russion tax number on https://tin-check.com/ They an API and you can also perform validation for more than 100 countries.
May be a good option.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex Filipovici |
Solution 2 | Sergei Panfilov |
Solution 3 | N Martins |