1 | import { buildMessage, ValidateBy } from '../common/ValidateBy';
|
2 | import isPostalCodeValidator from 'validator/lib/isPostalCode';
|
3 | export const IS_POSTAL_CODE = 'isPostalCode';
|
4 | /**
|
5 | * Check if the string is a postal code,
|
6 | * (locale is one of [ 'AD', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ] OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is validator.isPostalCodeLocales.).
|
7 | * If given value is not a string, then it returns false.
|
8 | */
|
9 | export function isPostalCode(value, locale) {
|
10 | return typeof value === 'string' && isPostalCodeValidator(value, locale);
|
11 | }
|
12 | /**
|
13 | * Check if the string is a postal code,
|
14 | * (locale is one of [ 'AD', 'AT', 'AU', 'BE', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'ID', 'IE' 'IL', 'IN', 'IR', 'IS', 'IT', 'JP', 'KE', 'LI', 'LT', 'LU', 'LV', 'MT', 'MX', 'NL', 'NO', 'NZ', 'PL', 'PR', 'PT', 'RO', 'RU', 'SA', 'SE', 'SI', 'TN', 'TW', 'UA', 'US', 'ZA', 'ZM' ] OR 'any'. If 'any' is used, function will check if any of the locals match. Locale list is validator.isPostalCodeLocales.).
|
15 | * If given value is not a string, then it returns false.
|
16 | */
|
17 | export function IsPostalCode(locale, validationOptions) {
|
18 | return ValidateBy({
|
19 | name: IS_POSTAL_CODE,
|
20 | constraints: [locale],
|
21 | validator: {
|
22 | validate: (value, args) => isPostalCode(value, args.constraints[0]),
|
23 | defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a postal code', validationOptions),
|
24 | },
|
25 | }, validationOptions);
|
26 | }
|
27 | //# sourceMappingURL=IsPostalCode.js.map |
\ | No newline at end of file |