polish-validators
Version:
A set of validator functions that check common polish numbers.
29 lines (28 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPostalCodeInvalid = exports.isPostalCodeValid = void 0;
const POSTAL_CODE_REGEX = /^\d{2}-?\d{3}$/;
/**
* Validates a Polish postal code format. This function checks that the code follows
* the format `XX-XXX`, where each `X` is a digit. The dash in the format is optional,
* but putting a dash in the wrong place will result in the code being invalid.
* This function does not validate whether a code actually exists.
*
* @param {string} code - The postal code as a string.
* @returns {boolean} `true` if the postal code format is valid; `false` otherwise.
*/
function isPostalCodeValid(code) {
return POSTAL_CODE_REGEX.test(code);
}
exports.isPostalCodeValid = isPostalCodeValid;
/**
* Validates a Polish postal code format. This function checks that the code follows
* the format `XX-XXX`, where each `X` is a digit. The dash in the format is optional,
* but putting a dash in the wrong place will result in the code being invalid.
* This function does not validate whether a code actually exists.
*
* @param {string} code - The postal code as a string.
* @returns {boolean} `true` if the postal code format is invalid; `false` otherwise.
*/
const isPostalCodeInvalid = (code) => !isPostalCodeValid(code);
exports.isPostalCodeInvalid = isPostalCodeInvalid;