Zum Hauptinhalt springen

VatValidatorRegex

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

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

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

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

Constructors

Constructor

new VatValidatorRegex(): VatValidatorRegex

Returns

VatValidatorRegex

Methods

isValid()

static isValid(vat): boolean

Validates a VAT.

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

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

Parameters

vat

string

an unformatted vat string

Returns

boolean

true if valid, otherwise false


validate()

static validate(vat): boolean

Validates a VAT.

Warning: This function will throws error.

try {
const isValid = VatValidatorRegex.validate("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