Zum Hauptinhalt springen

VatValidator

This class validates and formats VAT numbers. There's also a online validator service available (uses http://ec.europa.eu).

context.enableModules();
const { VatValidator } = require("ou.sp.validation.VatValidator");

const isValid = VatValidator.isValid("de-306219982");
// Validate online.
const isValid = VatValidator.isValid("de-306219982", true);

try {
const isValid = VatValidator.validate("de-306219982", true);
} catch (error) {
util.log(error.message);
}

Constructors​

Constructor​

new VatValidator(): VatValidator

Returns​

VatValidator

Methods​

isValidByPattern()​

static isValidByPattern(vat): boolean

Validates a VAT by using regular expressions

Warning: This function will not throw an error. If an error occurs, this function will always return false

const isValid = VatValidator.isValid("de-306219982");
// isValid = true

Parameters​

vat​

string

an unformatted vat string

Returns​

boolean

true if valid, otherwise false


isValidByUsingEUService()​

static isValidByUsingEUService(vat): boolean

Validates a VAT by using the http://ec.europa.eu API.

Warning: This function will not throw an error. If an error occurs, this function will always return false

const isValid = VatValidator.isValid("de-306219982");
// isValid = true

Parameters​

vat​

string

an unformatted vat string

Returns​

boolean

true if valid, otherwise false


isValidByUsingBzStService()​

Call Signature​

static isValidByUsingBzStService(ownerVat, companyVat): boolean

Validates a VAT by using the german Federal Central Tax Office service (https://evatr.bff-online.de/eVatR/).

Warning: This function will not throw an error. If an error occurs, this function will always return false

const isValid = VatValidator.isValidByUsingBzStService("DE306219982","NL809075349B01");
// isValid = true
Parameters​
ownerVat​

string

companyVat​

string

Returns​

boolean

true if valid, otherwise false

Call Signature​

static isValidByUsingBzStService(ownerVat, companyVat, companyName, companyCity, companyZipCode?, companyStreet?): boolean

Validates a VAT by using the german Federal Central Tax Office service (https://evatr.bff-online.de/eVatR/).

Warning: This function will not throw an error. If an error occurs, this function will always return false

const isValid = VatValidator.isValidByUsingBzStService("DE306219982","NL809075349B01","WILDLANDS Adventure Zoo Emmen B.V","Emmen","Raadhuisplein 99");
// isValid = true
Parameters​
ownerVat​

string

companyVat​

string

companyName​

string

companyCity​

string

companyZipCode?​

string

companyStreet?​

string

Returns​

boolean

true if valid, otherwise false


validateByPattern()​

static validateByPattern(vat): boolean

Validates a VAT.

Warning: This function will throws error.

try {
const isValid = VatValidator.validateByPattern("de-306219982");
// isValid = true
} catch(error) {
// handle error
}

Parameters​

vat​

string

an unformatted vat string

Returns​

boolean

true if valid, otherwise false

Throws​

an error in case of any error


validateByUsingEUService()​

static validateByUsingEUService(vat): boolean

Validates a VAT by using the http://ec.europa.eu API.

Warning: This function will throws error.

try {
const isValid = VatValidator.validateByUsingEUService("de-306219982");
// isValid = true
} catch(error) {
// handle error
}

Parameters​

vat​

string

an unformatted vat string

Returns​

boolean

true if valid, otherwise false

Throws​

an error in case of any error


validateByUsingBzStService()​

Call Signature​

static validateByUsingBzStService(ownerVat, companyVat): BzStServiceResponse

Validates a VAT by using the german Federal Central Tax Office service (https://evatr.bff-online.de/eVatR/).

Warning: This function will throws error.

const result = VatValidator.validateByUsingBzStService("DE306219982","NL809075349B01","WILDLANDS Adventure Zoo Emmen B.V","Emmen","Raadhuisplein 99");
// {
// "UstId_1": "DE306219982",
// "UstId_2": "NL809075349B01",
// "ErrorCode": "200",
// "ErrorMessage": "Die angefragte USt-IdNr. ist gültig.",
// "Firmenname": "WILDLANDS Adventure Zoo Emmen B.V",
// "Druck": "nein",
// "Strasse": "Raadhuisplein 99",
// "Ort": "Emmen",
// "Datum": "01.12.2022",
// "PLZ": "",
// "Uhrzeit": "13:48:43",
// "Gueltig_ab": "",
// "Gueltig_bis": "",
// "Erg_Ort": "A",
// "Erg_PLZ": "C",
// "Erg_Name": "A",
// "Erg_Str": "A"
// }
Parameters​
ownerVat​

string

the owner vat

companyVat​

string

the company vat

Returns​

BzStServiceResponse

true if valid, otherwise false

Throws​

an error in case of any error

Call Signature​

static validateByUsingBzStService(ownerVat, companyVat, companyName, companyCity, companyZipCode?, companyStreet?): BzStServiceResponse

Validates a VAT by using the german Federal Central Tax Office service (https://evatr.bff-online.de/eVatR/).

Warning: This function will throws error.

const result = VatValidator.validateByUsingBzStService("DE306219982","NL809075349B01","WILDLANDS Adventure Zoo Emmen B.V","Emmen","Raadhuisplein 99");
// {
// "UstId_1": "DE306219982",
// "UstId_2": "NL809075349B01",
// "ErrorCode": "200",
// "ErrorMessage": "Die angefragte USt-IdNr. ist gültig.",
// "Firmenname": "WILDLANDS Adventure Zoo Emmen B.V",
// "Druck": "nein",
// "Strasse": "Raadhuisplein 99",
// "Ort": "Emmen",
// "Datum": "01.12.2022",
// "PLZ": "",
// "Uhrzeit": "13:48:43",
// "Gueltig_ab": "",
// "Gueltig_bis": "",
// "Erg_Ort": "A",
// "Erg_PLZ": "C",
// "Erg_Name": "A",
// "Erg_Str": "A"
// }
Parameters​
ownerVat​

string

the owner vat

companyVat​

string

the company vat

companyName​

string

the company name

companyCity​

string

the company city

companyZipCode?​

string

the company zip code

companyStreet?​

string

the company street

Returns​

BzStServiceResponse

true if valid, otherwise false

Throws​

an error in case of any error


format()​

static format(vat): string

Formats the provided VAT

const formatted = VatValidator.format("de-306219982");
// "DE306219982"

Parameters​

vat​

string

Returns​

string