You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(geo): add validateZipCode api in geo module [ROW-575] (#233)
* feat(geo): add validateZipCode function to geo module
Introduce validateZipCode function to validate zip codes against supported countries.
* docs: replace add validateZipCode API documentation
* Create slimy-gifts-melt.md
* fix(geo): export validateZipCode function from geo module
Copy file name to clipboardExpand all lines: packages/i18nify-js/README.md
+60-2Lines changed: 60 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -265,7 +265,7 @@ console.log(
265
265
locale:'fr-FR',
266
266
}),
267
267
); /* {
268
-
"integer": "12345",
268
+
"integer": "12345",
269
269
"decimal": ",",
270
270
"fraction": "67",
271
271
"currency": "€",
@@ -277,7 +277,7 @@ console.log(
277
277
},
278
278
{
279
279
"type": "group",
280
-
"value": ""
280
+
"value": ""
281
281
},
282
282
{
283
283
"type": "integer",
@@ -1116,6 +1116,64 @@ try {
1116
1116
}
1117
1117
```
1118
1118
1119
+
#### validateZipCode(zipcode, countryCode?) 🔍
1120
+
1121
+
The `validateZipCode` API helps you verify if a zipcode exists in a specific country or across all supported countries. This function is particularly useful for address validation, form verification, and ensuring postal codes are valid before processing.
1122
+
1123
+
##### Parameters
1124
+
1125
+
-`zipcode` (string): The zipcode to validate
1126
+
-`countryCode` (optional, string): The country code to validate against. If not provided, searches across all supported countries.
1127
+
1128
+
##### Returns
1129
+
1130
+
Promise that resolves to:
1131
+
1132
+
-`true` if the zipcode exists in the specified country (or any country if no country code is provided)
// Outputs: Invalid country code: XYZ. Please ensure you provide a valid country code.
1156
+
}
1157
+
1158
+
// Handling empty zipcodes
1159
+
try {
1160
+
awaitvalidateZipCode('');
1161
+
} catch (error) {
1162
+
console.error(error.message);
1163
+
// Outputs: Zipcode is required. Please provide a valid zipcode.
1164
+
}
1165
+
```
1166
+
1167
+
##### Error Handling
1168
+
1169
+
The API throws errors in the following cases:
1170
+
1171
+
- When the zipcode is empty or contains only whitespace
1172
+
- When an invalid country code is provided
1173
+
- When the API request fails while searching in a specific country
1174
+
1175
+
For multi-country searches (when no country code is provided), errors are silently handled by returning `false`, allowing the search to continue with other countries.
1176
+
1119
1177
#### getFlagOfCountry(countryCode) 🏁
1120
1178
1121
1179
Source for flag images: [FlagCDN](https://flagcdn.com/).
0 commit comments