/** * Cuban Passport Number (Pasaporte cubano). * * Format: One uppercase letter followed by six digits (format X999999), total 7 characters. Cuban passports are not ICAO/EU compliant and there is no Microsoft Purview SIT for Cuba; the letter+6-digit pattern comes from secondary identifier/passport-format references rather than a primary government source. * * Source * https://en.wikipedia.org/wiki/Cuban_passport * https://travel.state.gov/content/travel/en/us-visas/Visa-Reciprocity-and-Civil-Documents-by-Country/Cuba.html * * PERSON */ import * as exceptions from '../exceptions'; import { strings } from '../util'; import { Validator, ValidateReturn } from '../types'; function clean(input: string): ReturnType { return strings.cleanUnicode(input, ' -./,'); } const idRegexp = /^[A-Z]\d{6}$/; const impl: Validator = { name: 'Cuban Passport Number', localName: 'Pasaporte cubano', abbreviation: 'Passport', examples: ['C123456'], formats: ['annnnnn'], 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; }, validate(input: string): ValidateReturn { const [value, error] = clean(input); if (error) { return { isValid: false, error }; } if (value.length !== 7) { return { isValid: false, error: new exceptions.InvalidLength() }; } const match = value.match(idRegexp); if (!match) { return { isValid: false, error: new exceptions.InvalidFormat() }; } return { isValid: true, compact: value, isIndividual: true, isCompany: false, }; }, }; export const { name, localName, abbreviation, examples, formats, validate, format, compact, } = impl;