/** * * Austrian Company Register Numbers. * * Sources: * * ENTITY * */ import * as exceptions from '../exceptions'; import { strings } from '../util'; import { Validator, ValidateReturn } from '../types'; function clean(input: string): ReturnType { const [value, err] = strings.cleanUnicode(input, ' -./'); if (err) { return [value, err]; } if (value.startsWith('FN')) { return [value.substring(2), null]; } return [value, null]; } const impl: Validator = { name: 'Austrian Company Register Number', localName: 'Company Register Number', examples: ['122119M'], formats: [ 'nnnnnna', 'nnnnna', 'nnnnnnna', 'nnnna', 'nnnnnnnna', 'nnna', 'nnnnnnnnna', 'na', 'nna', ], compact(input: string): string { const [value, err] = clean(input); if (err) { throw err; } return value; }, format(input: string): string { const [value] = clean(input); return value; }, /** * Check if the number is a valid Business ID number. * This checks the length, formatting and other contraints. It does not check * for control letter. */ validate(input: string): ValidateReturn { const [value, error] = clean(input); if (error) { return { isValid: false, error }; } if (!/^\d+[A-Z]$/.test(value)) { return { isValid: false, error: new exceptions.InvalidFormat() }; } return { isValid: true, compact: value, isIndividual: false, isCompany: true, }; }, }; export const { name, localName, abbreviation, examples, formats, validate, format, compact, } = impl;