@obosbbl/validation
Version:
A collection of validation methods for OBOS
73 lines (69 loc) • 2.6 kB
text/typescript
export { validateObosMembershipNumber } from './no.mjs';
type ValidatorOptions = {
/**
* Allow formatting characters
* @default false
*/
allowFormatting?: boolean;
};
type PostalCodeOptions = ValidatorOptions;
/**
* Validates that the input value is a Swedish postal (zip) code.
* @example
* ```
* validatePostalCode('00000') // => true
* ```
*/
declare function validatePostalCode(value: string, options?: PostalCodeOptions): boolean;
type PhoneNumberOptions = ValidatorOptions & {
/**
* Whether it should be a mobile number
* @default false
*/
mobileOnly?: boolean;
};
/**
* Validates that the input value is a Swedish phone number.
*
* Supports mobile only validation.
* @example
* ```
* validatePhoneNumber('00000000') // => true
* validatePhoneNumber('000000000') // => true
* validatePhoneNumber('0000000000') // => true
* validatePhoneNumber('0700000000', { mobileOnly: true }) // => true
* ```
*/
declare function validatePhoneNumber(value: string, options?: PhoneNumberOptions): boolean;
type OrganizationNumberOptions = ValidatorOptions;
/**
* Validates that the input value is a {@link https://www.skatteverket.se/foretagochorganisationer/foretagare/startaochregistrera/organisationsnummer.4.361dc8c15312eff6fd235d1.html Swedish organization number}.
* @example
* ```
* validateOrganizationNumber('000000000') // => true
* ```
*/
declare function validateOrganizationNumber(value: string, options?: OrganizationNumberOptions): boolean;
type NationalIdentityNumberFormat = 'short' | 'long';
type NationalIdentityNumberOptions = ValidatorOptions & {
/** Specify this if you want to format to be only long (12 digits) or short (10 digits). By default, both formats are allowed */
format?: NationalIdentityNumberFormat;
};
/**
* Validates that the input value is a Swedish national identity number (personnummer or samordningsnummer).
*
* It validates the control digits and checks if the date of birth is valid.
*
* @example
* ```
* // Short format
* validatePersonalIdentityNumber('YYMMDDXXXX') // => true
* validatePersonalIdentityNumber('YYMMDD-XXXX', { allowFormatting: true }) // => true
*
* // Long format
* validatePersonalIdentityNumber('YYYYMMDDXXXX') // => true
* validatePersonalIdentityNumber('YYYYMMDD-XXXX', { allowFormatting: true }) // => true
* ```
*/
declare function validateNationalIdentityNumber(value: string, options?: NationalIdentityNumberOptions): boolean;
export { validateNationalIdentityNumber, validateOrganizationNumber, validatePhoneNumber, validatePostalCode };