@hy_ong/zod-kit 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +38 -26
- package/dist/index.d.cts +22 -26
- package/dist/index.d.ts +22 -26
- package/dist/index.js +38 -26
- package/package.json +1 -1
- package/src/validators/taiwan/fax.ts +52 -48
- package/src/validators/taiwan/tel.ts +52 -48
package/dist/index.cjs
CHANGED
|
@@ -3326,37 +3326,43 @@ var validateTaiwanTel = (value) => {
|
|
|
3326
3326
|
return false;
|
|
3327
3327
|
}
|
|
3328
3328
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3329
|
-
if (areaCode4 === "0826") {
|
|
3330
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue);
|
|
3331
|
-
}
|
|
3332
3329
|
if (areaCode4 === "0836") {
|
|
3333
|
-
return cleanValue.length === 9 && /^0836
|
|
3330
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3334
3331
|
}
|
|
3335
3332
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3336
3333
|
if (areaCode3 === "037") {
|
|
3337
|
-
return cleanValue.length === 9 && /^037
|
|
3334
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue);
|
|
3338
3335
|
}
|
|
3339
3336
|
if (areaCode3 === "049") {
|
|
3340
|
-
return cleanValue.length === 10 && /^049
|
|
3337
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3341
3338
|
}
|
|
3342
3339
|
if (areaCode3 === "082") {
|
|
3343
|
-
return cleanValue.length === 9 && /^082
|
|
3340
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
3344
3341
|
}
|
|
3345
3342
|
if (areaCode3 === "089") {
|
|
3346
|
-
return cleanValue.length === 9 && /^089
|
|
3343
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue);
|
|
3347
3344
|
}
|
|
3348
3345
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3349
3346
|
if (areaCode2 === "02") {
|
|
3350
|
-
return cleanValue.length === 10 && /^02
|
|
3347
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue);
|
|
3348
|
+
}
|
|
3349
|
+
if (areaCode2 === "03") {
|
|
3350
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
3351
|
+
}
|
|
3352
|
+
if (areaCode2 === "04") {
|
|
3353
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue);
|
|
3354
|
+
}
|
|
3355
|
+
if (areaCode2 === "05") {
|
|
3356
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue);
|
|
3351
3357
|
}
|
|
3352
|
-
if (
|
|
3353
|
-
return cleanValue.length === 9;
|
|
3358
|
+
if (areaCode2 === "06") {
|
|
3359
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3354
3360
|
}
|
|
3355
3361
|
if (areaCode2 === "07") {
|
|
3356
|
-
return cleanValue.length === 9 && /^07
|
|
3362
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue);
|
|
3357
3363
|
}
|
|
3358
3364
|
if (areaCode2 === "08") {
|
|
3359
|
-
return cleanValue.length === 9 && /^08
|
|
3365
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue);
|
|
3360
3366
|
}
|
|
3361
3367
|
return false;
|
|
3362
3368
|
};
|
|
@@ -3426,37 +3432,43 @@ var validateTaiwanFax = (value) => {
|
|
|
3426
3432
|
return false;
|
|
3427
3433
|
}
|
|
3428
3434
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3429
|
-
if (areaCode4 === "0826") {
|
|
3430
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue);
|
|
3431
|
-
}
|
|
3432
3435
|
if (areaCode4 === "0836") {
|
|
3433
|
-
return cleanValue.length === 9 && /^0836
|
|
3436
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3434
3437
|
}
|
|
3435
3438
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3436
3439
|
if (areaCode3 === "037") {
|
|
3437
|
-
return cleanValue.length === 9 && /^037
|
|
3440
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue);
|
|
3438
3441
|
}
|
|
3439
3442
|
if (areaCode3 === "049") {
|
|
3440
|
-
return cleanValue.length === 10 && /^049
|
|
3443
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3441
3444
|
}
|
|
3442
3445
|
if (areaCode3 === "082") {
|
|
3443
|
-
return cleanValue.length === 9 && /^082
|
|
3446
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
3444
3447
|
}
|
|
3445
3448
|
if (areaCode3 === "089") {
|
|
3446
|
-
return cleanValue.length === 9 && /^089
|
|
3449
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue);
|
|
3447
3450
|
}
|
|
3448
3451
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3449
3452
|
if (areaCode2 === "02") {
|
|
3450
|
-
return cleanValue.length === 10 && /^02
|
|
3453
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue);
|
|
3454
|
+
}
|
|
3455
|
+
if (areaCode2 === "03") {
|
|
3456
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
3457
|
+
}
|
|
3458
|
+
if (areaCode2 === "04") {
|
|
3459
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue);
|
|
3460
|
+
}
|
|
3461
|
+
if (areaCode2 === "05") {
|
|
3462
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue);
|
|
3451
3463
|
}
|
|
3452
|
-
if (
|
|
3453
|
-
return cleanValue.length === 9;
|
|
3464
|
+
if (areaCode2 === "06") {
|
|
3465
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3454
3466
|
}
|
|
3455
3467
|
if (areaCode2 === "07") {
|
|
3456
|
-
return cleanValue.length === 9 && /^07
|
|
3468
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue);
|
|
3457
3469
|
}
|
|
3458
3470
|
if (areaCode2 === "08") {
|
|
3459
|
-
return cleanValue.length === 9 && /^08
|
|
3471
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue);
|
|
3460
3472
|
}
|
|
3461
3473
|
return false;
|
|
3462
3474
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -2898,28 +2898,26 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2898
2898
|
* number patterns.
|
|
2899
2899
|
*
|
|
2900
2900
|
* Supported area codes and formats:
|
|
2901
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2902
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
2903
|
-
* - 037: Miaoli - 6 digits
|
|
2904
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
2905
|
-
* - 049: Nantou - 7 digits
|
|
2901
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2902
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2903
|
+
* - 037: Miaoli - 6-7 digits
|
|
2904
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2905
|
+
* - 049: Nantou - 7 digits
|
|
2906
2906
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
2907
2907
|
* - 06: Tainan - 7 digits
|
|
2908
|
-
* - 07: Kaohsiung - 7 digits
|
|
2909
|
-
* - 08: Pingtung - 7 digits
|
|
2910
|
-
* - 082: Kinmen - 6 digits
|
|
2911
|
-
* -
|
|
2912
|
-
* -
|
|
2913
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
2908
|
+
* - 07: Kaohsiung - 7 digits
|
|
2909
|
+
* - 08: Pingtung - 7 digits
|
|
2910
|
+
* - 082: Kinmen - 6 digits
|
|
2911
|
+
* - 0836: Matsu - 5 digits
|
|
2912
|
+
* - 089: Taitung - 6 digits
|
|
2914
2913
|
*
|
|
2915
2914
|
* @example
|
|
2916
2915
|
* ```typescript
|
|
2917
2916
|
* validateTaiwanTel("0223456789") // true (Taipei area)
|
|
2918
|
-
* validateTaiwanTel("
|
|
2917
|
+
* validateTaiwanTel("0423288882") // true (Taichung area, 8 digits)
|
|
2919
2918
|
* validateTaiwanTel("037234567") // true (Miaoli area)
|
|
2920
2919
|
* validateTaiwanTel("082234567") // true (Kinmen area)
|
|
2921
2920
|
* validateTaiwanTel("02-2345-6789") // true (with separators)
|
|
2922
|
-
* validateTaiwanTel("0812345678") // false (invalid for 08 area)
|
|
2923
2921
|
* ```
|
|
2924
2922
|
*/
|
|
2925
2923
|
declare const validateTaiwanTel: (value: string) => boolean;
|
|
@@ -3055,27 +3053,25 @@ type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
3055
3053
|
* Fax numbers follow the same format as landline telephone numbers in Taiwan.
|
|
3056
3054
|
*
|
|
3057
3055
|
* Supported area codes and formats (same as landline):
|
|
3058
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3059
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
3060
|
-
* - 037: Miaoli - 6 digits
|
|
3061
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
3062
|
-
* - 049: Nantou - 7 digits
|
|
3056
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3057
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
3058
|
+
* - 037: Miaoli - 6-7 digits
|
|
3059
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
3060
|
+
* - 049: Nantou - 7 digits
|
|
3063
3061
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
3064
3062
|
* - 06: Tainan - 7 digits
|
|
3065
|
-
* - 07: Kaohsiung - 7 digits
|
|
3066
|
-
* - 08: Pingtung - 7 digits
|
|
3067
|
-
* - 082: Kinmen - 6 digits
|
|
3068
|
-
* -
|
|
3069
|
-
* -
|
|
3070
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
3063
|
+
* - 07: Kaohsiung - 7 digits
|
|
3064
|
+
* - 08: Pingtung - 7 digits
|
|
3065
|
+
* - 082: Kinmen - 6 digits
|
|
3066
|
+
* - 0836: Matsu - 5 digits
|
|
3067
|
+
* - 089: Taitung - 6 digits
|
|
3071
3068
|
*
|
|
3072
3069
|
* @example
|
|
3073
3070
|
* ```typescript
|
|
3074
3071
|
* validateTaiwanFax("0223456789") // true (Taipei area)
|
|
3075
|
-
* validateTaiwanFax("
|
|
3072
|
+
* validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
|
|
3076
3073
|
* validateTaiwanFax("037234567") // true (Miaoli area)
|
|
3077
3074
|
* validateTaiwanFax("02-2345-6789") // true (with separators)
|
|
3078
|
-
* validateTaiwanFax("0812345678") // false (invalid for 08 area)
|
|
3079
3075
|
* ```
|
|
3080
3076
|
*/
|
|
3081
3077
|
declare const validateTaiwanFax: (value: string) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -2898,28 +2898,26 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2898
2898
|
* number patterns.
|
|
2899
2899
|
*
|
|
2900
2900
|
* Supported area codes and formats:
|
|
2901
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2902
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
2903
|
-
* - 037: Miaoli - 6 digits
|
|
2904
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
2905
|
-
* - 049: Nantou - 7 digits
|
|
2901
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2902
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2903
|
+
* - 037: Miaoli - 6-7 digits
|
|
2904
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2905
|
+
* - 049: Nantou - 7 digits
|
|
2906
2906
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
2907
2907
|
* - 06: Tainan - 7 digits
|
|
2908
|
-
* - 07: Kaohsiung - 7 digits
|
|
2909
|
-
* - 08: Pingtung - 7 digits
|
|
2910
|
-
* - 082: Kinmen - 6 digits
|
|
2911
|
-
* -
|
|
2912
|
-
* -
|
|
2913
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
2908
|
+
* - 07: Kaohsiung - 7 digits
|
|
2909
|
+
* - 08: Pingtung - 7 digits
|
|
2910
|
+
* - 082: Kinmen - 6 digits
|
|
2911
|
+
* - 0836: Matsu - 5 digits
|
|
2912
|
+
* - 089: Taitung - 6 digits
|
|
2914
2913
|
*
|
|
2915
2914
|
* @example
|
|
2916
2915
|
* ```typescript
|
|
2917
2916
|
* validateTaiwanTel("0223456789") // true (Taipei area)
|
|
2918
|
-
* validateTaiwanTel("
|
|
2917
|
+
* validateTaiwanTel("0423288882") // true (Taichung area, 8 digits)
|
|
2919
2918
|
* validateTaiwanTel("037234567") // true (Miaoli area)
|
|
2920
2919
|
* validateTaiwanTel("082234567") // true (Kinmen area)
|
|
2921
2920
|
* validateTaiwanTel("02-2345-6789") // true (with separators)
|
|
2922
|
-
* validateTaiwanTel("0812345678") // false (invalid for 08 area)
|
|
2923
2921
|
* ```
|
|
2924
2922
|
*/
|
|
2925
2923
|
declare const validateTaiwanTel: (value: string) => boolean;
|
|
@@ -3055,27 +3053,25 @@ type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
3055
3053
|
* Fax numbers follow the same format as landline telephone numbers in Taiwan.
|
|
3056
3054
|
*
|
|
3057
3055
|
* Supported area codes and formats (same as landline):
|
|
3058
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3059
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
3060
|
-
* - 037: Miaoli - 6 digits
|
|
3061
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
3062
|
-
* - 049: Nantou - 7 digits
|
|
3056
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3057
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
3058
|
+
* - 037: Miaoli - 6-7 digits
|
|
3059
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
3060
|
+
* - 049: Nantou - 7 digits
|
|
3063
3061
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
3064
3062
|
* - 06: Tainan - 7 digits
|
|
3065
|
-
* - 07: Kaohsiung - 7 digits
|
|
3066
|
-
* - 08: Pingtung - 7 digits
|
|
3067
|
-
* - 082: Kinmen - 6 digits
|
|
3068
|
-
* -
|
|
3069
|
-
* -
|
|
3070
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
3063
|
+
* - 07: Kaohsiung - 7 digits
|
|
3064
|
+
* - 08: Pingtung - 7 digits
|
|
3065
|
+
* - 082: Kinmen - 6 digits
|
|
3066
|
+
* - 0836: Matsu - 5 digits
|
|
3067
|
+
* - 089: Taitung - 6 digits
|
|
3071
3068
|
*
|
|
3072
3069
|
* @example
|
|
3073
3070
|
* ```typescript
|
|
3074
3071
|
* validateTaiwanFax("0223456789") // true (Taipei area)
|
|
3075
|
-
* validateTaiwanFax("
|
|
3072
|
+
* validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
|
|
3076
3073
|
* validateTaiwanFax("037234567") // true (Miaoli area)
|
|
3077
3074
|
* validateTaiwanFax("02-2345-6789") // true (with separators)
|
|
3078
|
-
* validateTaiwanFax("0812345678") // false (invalid for 08 area)
|
|
3079
3075
|
* ```
|
|
3080
3076
|
*/
|
|
3081
3077
|
declare const validateTaiwanFax: (value: string) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -3248,37 +3248,43 @@ var validateTaiwanTel = (value) => {
|
|
|
3248
3248
|
return false;
|
|
3249
3249
|
}
|
|
3250
3250
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3251
|
-
if (areaCode4 === "0826") {
|
|
3252
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue);
|
|
3253
|
-
}
|
|
3254
3251
|
if (areaCode4 === "0836") {
|
|
3255
|
-
return cleanValue.length === 9 && /^0836
|
|
3252
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3256
3253
|
}
|
|
3257
3254
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3258
3255
|
if (areaCode3 === "037") {
|
|
3259
|
-
return cleanValue.length === 9 && /^037
|
|
3256
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue);
|
|
3260
3257
|
}
|
|
3261
3258
|
if (areaCode3 === "049") {
|
|
3262
|
-
return cleanValue.length === 10 && /^049
|
|
3259
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3263
3260
|
}
|
|
3264
3261
|
if (areaCode3 === "082") {
|
|
3265
|
-
return cleanValue.length === 9 && /^082
|
|
3262
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
3266
3263
|
}
|
|
3267
3264
|
if (areaCode3 === "089") {
|
|
3268
|
-
return cleanValue.length === 9 && /^089
|
|
3265
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue);
|
|
3269
3266
|
}
|
|
3270
3267
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3271
3268
|
if (areaCode2 === "02") {
|
|
3272
|
-
return cleanValue.length === 10 && /^02
|
|
3269
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue);
|
|
3270
|
+
}
|
|
3271
|
+
if (areaCode2 === "03") {
|
|
3272
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
3273
|
+
}
|
|
3274
|
+
if (areaCode2 === "04") {
|
|
3275
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue);
|
|
3276
|
+
}
|
|
3277
|
+
if (areaCode2 === "05") {
|
|
3278
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue);
|
|
3273
3279
|
}
|
|
3274
|
-
if (
|
|
3275
|
-
return cleanValue.length === 9;
|
|
3280
|
+
if (areaCode2 === "06") {
|
|
3281
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3276
3282
|
}
|
|
3277
3283
|
if (areaCode2 === "07") {
|
|
3278
|
-
return cleanValue.length === 9 && /^07
|
|
3284
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue);
|
|
3279
3285
|
}
|
|
3280
3286
|
if (areaCode2 === "08") {
|
|
3281
|
-
return cleanValue.length === 9 && /^08
|
|
3287
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue);
|
|
3282
3288
|
}
|
|
3283
3289
|
return false;
|
|
3284
3290
|
};
|
|
@@ -3348,37 +3354,43 @@ var validateTaiwanFax = (value) => {
|
|
|
3348
3354
|
return false;
|
|
3349
3355
|
}
|
|
3350
3356
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3351
|
-
if (areaCode4 === "0826") {
|
|
3352
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue);
|
|
3353
|
-
}
|
|
3354
3357
|
if (areaCode4 === "0836") {
|
|
3355
|
-
return cleanValue.length === 9 && /^0836
|
|
3358
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3356
3359
|
}
|
|
3357
3360
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3358
3361
|
if (areaCode3 === "037") {
|
|
3359
|
-
return cleanValue.length === 9 && /^037
|
|
3362
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue);
|
|
3360
3363
|
}
|
|
3361
3364
|
if (areaCode3 === "049") {
|
|
3362
|
-
return cleanValue.length === 10 && /^049
|
|
3365
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3363
3366
|
}
|
|
3364
3367
|
if (areaCode3 === "082") {
|
|
3365
|
-
return cleanValue.length === 9 && /^082
|
|
3368
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
3366
3369
|
}
|
|
3367
3370
|
if (areaCode3 === "089") {
|
|
3368
|
-
return cleanValue.length === 9 && /^089
|
|
3371
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue);
|
|
3369
3372
|
}
|
|
3370
3373
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3371
3374
|
if (areaCode2 === "02") {
|
|
3372
|
-
return cleanValue.length === 10 && /^02
|
|
3375
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue);
|
|
3376
|
+
}
|
|
3377
|
+
if (areaCode2 === "03") {
|
|
3378
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
3379
|
+
}
|
|
3380
|
+
if (areaCode2 === "04") {
|
|
3381
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue);
|
|
3382
|
+
}
|
|
3383
|
+
if (areaCode2 === "05") {
|
|
3384
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue);
|
|
3373
3385
|
}
|
|
3374
|
-
if (
|
|
3375
|
-
return cleanValue.length === 9;
|
|
3386
|
+
if (areaCode2 === "06") {
|
|
3387
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3376
3388
|
}
|
|
3377
3389
|
if (areaCode2 === "07") {
|
|
3378
|
-
return cleanValue.length === 9 && /^07
|
|
3390
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue);
|
|
3379
3391
|
}
|
|
3380
3392
|
if (areaCode2 === "08") {
|
|
3381
|
-
return cleanValue.length === 9 && /^08
|
|
3393
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue);
|
|
3382
3394
|
}
|
|
3383
3395
|
return false;
|
|
3384
3396
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hy_ong/zod-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A comprehensive TypeScript library providing pre-built Zod validation schemas with full internationalization support for common data types and Taiwan-specific formats",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -65,44 +65,41 @@ export type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ?
|
|
|
65
65
|
* Fax numbers follow the same format as landline telephone numbers in Taiwan.
|
|
66
66
|
*
|
|
67
67
|
* Supported area codes and formats (same as landline):
|
|
68
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
69
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
70
|
-
* - 037: Miaoli - 6 digits
|
|
71
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
72
|
-
* - 049: Nantou - 7 digits
|
|
68
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
69
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
70
|
+
* - 037: Miaoli - 6-7 digits
|
|
71
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
72
|
+
* - 049: Nantou - 7 digits
|
|
73
73
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
74
74
|
* - 06: Tainan - 7 digits
|
|
75
|
-
* - 07: Kaohsiung - 7 digits
|
|
76
|
-
* - 08: Pingtung - 7 digits
|
|
77
|
-
* - 082: Kinmen - 6 digits
|
|
78
|
-
* -
|
|
79
|
-
* -
|
|
80
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
75
|
+
* - 07: Kaohsiung - 7 digits
|
|
76
|
+
* - 08: Pingtung - 7 digits
|
|
77
|
+
* - 082: Kinmen - 6 digits
|
|
78
|
+
* - 0836: Matsu - 5 digits
|
|
79
|
+
* - 089: Taitung - 6 digits
|
|
81
80
|
*
|
|
82
81
|
* @example
|
|
83
82
|
* ```typescript
|
|
84
83
|
* validateTaiwanFax("0223456789") // true (Taipei area)
|
|
85
|
-
* validateTaiwanFax("
|
|
84
|
+
* validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
|
|
86
85
|
* validateTaiwanFax("037234567") // true (Miaoli area)
|
|
87
86
|
* validateTaiwanFax("02-2345-6789") // true (with separators)
|
|
88
|
-
* validateTaiwanFax("0812345678") // false (invalid for 08 area)
|
|
89
87
|
* ```
|
|
90
88
|
*/
|
|
91
89
|
const validateTaiwanFax = (value: string): boolean => {
|
|
92
90
|
// Official Taiwan fax formats according to telecom numbering plan (same as landline):
|
|
93
|
-
// 02: Taipei, New Taipei, Keelung - 8 digits
|
|
94
|
-
// 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
95
|
-
// 037: Miaoli - 6 digits
|
|
96
|
-
// 04: Taichung, Changhua - 7 digits
|
|
97
|
-
// 049: Nantou - 7 digits
|
|
91
|
+
// 02: Taipei, New Taipei, Keelung - 8 digits
|
|
92
|
+
// 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
93
|
+
// 037: Miaoli - 6-7 digits
|
|
94
|
+
// 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
95
|
+
// 049: Nantou - 7 digits
|
|
98
96
|
// 05: Yunlin, Chiayi - 7 digits
|
|
99
97
|
// 06: Tainan - 7 digits
|
|
100
|
-
// 07: Kaohsiung - 7 digits
|
|
101
|
-
// 08: Pingtung - 7 digits
|
|
102
|
-
// 082: Kinmen - 6 digits
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
// 089: Taitung - 6 digits (2~9+5D)
|
|
98
|
+
// 07: Kaohsiung - 7 digits
|
|
99
|
+
// 08: Pingtung - 7 digits
|
|
100
|
+
// 082: Kinmen - 6 digits
|
|
101
|
+
// 0836: Matsu - 5 digits
|
|
102
|
+
// 089: Taitung - 6 digits
|
|
106
103
|
|
|
107
104
|
// Remove common separators for validation
|
|
108
105
|
const cleanValue = value.replace(/[-\s]/g, "")
|
|
@@ -114,53 +111,60 @@ const validateTaiwanFax = (value: string): boolean => {
|
|
|
114
111
|
|
|
115
112
|
// Check 4-digit area codes first
|
|
116
113
|
const areaCode4 = cleanValue.substring(0, 4)
|
|
117
|
-
if (areaCode4 === '0826') {
|
|
118
|
-
// Wuqiu: 0826 + 5 digits (6+4D), total 9 digits
|
|
119
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue)
|
|
120
|
-
}
|
|
121
114
|
if (areaCode4 === '0836') {
|
|
122
|
-
// Matsu: 0836 + 5 digits
|
|
123
|
-
return cleanValue.length === 9 && /^0836
|
|
115
|
+
// Matsu: 0836 + 5 digits, total 9 digits
|
|
116
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue)
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
// Check 3-digit area codes
|
|
127
120
|
const areaCode3 = cleanValue.substring(0, 3)
|
|
128
121
|
if (areaCode3 === '037') {
|
|
129
|
-
// Miaoli: 037 + 6 digits
|
|
130
|
-
return cleanValue.length === 9 && /^037
|
|
122
|
+
// Miaoli: 037 + 6-7 digits, total 9-10 digits
|
|
123
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue)
|
|
131
124
|
}
|
|
132
125
|
if (areaCode3 === '049') {
|
|
133
|
-
// Nantou: 049 + 7 digits
|
|
134
|
-
return cleanValue.length === 10 && /^049
|
|
126
|
+
// Nantou: 049 + 7 digits, total 10 digits
|
|
127
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue)
|
|
135
128
|
}
|
|
136
129
|
if (areaCode3 === '082') {
|
|
137
|
-
// Kinmen: 082 + 6 digits
|
|
138
|
-
return cleanValue.length === 9 && /^082
|
|
130
|
+
// Kinmen: 082 + 6 digits, total 9 digits
|
|
131
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue)
|
|
139
132
|
}
|
|
140
133
|
if (areaCode3 === '089') {
|
|
141
|
-
// Taitung: 089 + 6 digits
|
|
142
|
-
return cleanValue.length === 9 && /^089
|
|
134
|
+
// Taitung: 089 + 6 digits, total 9 digits
|
|
135
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue)
|
|
143
136
|
}
|
|
144
137
|
|
|
145
138
|
// Check 2-digit area codes
|
|
146
139
|
const areaCode2 = cleanValue.substring(0, 2)
|
|
147
140
|
|
|
148
141
|
if (areaCode2 === '02') {
|
|
149
|
-
// Taipei, New Taipei, Keelung: 02 + 8 digits
|
|
150
|
-
return cleanValue.length === 10 && /^02
|
|
142
|
+
// Taipei, New Taipei, Keelung: 02 + 8 digits, total 10 digits
|
|
143
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue)
|
|
144
|
+
}
|
|
145
|
+
if (areaCode2 === '03') {
|
|
146
|
+
// Taoyuan, Hsinchu, Yilan, Hualien: 03 + 7-8 digits, total 9-10 digits
|
|
147
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue)
|
|
148
|
+
}
|
|
149
|
+
if (areaCode2 === '04') {
|
|
150
|
+
// Taichung, Changhua, Nantou: 04 + 7-8 digits, total 9-10 digits
|
|
151
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue)
|
|
152
|
+
}
|
|
153
|
+
if (areaCode2 === '05') {
|
|
154
|
+
// Yunlin, Chiayi: 05 + 7 digits, total 9 digits
|
|
155
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue)
|
|
151
156
|
}
|
|
152
|
-
if (
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
return cleanValue.length === 9
|
|
157
|
+
if (areaCode2 === '06') {
|
|
158
|
+
// Tainan: 06 + 7 digits, total 9 digits
|
|
159
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue)
|
|
156
160
|
}
|
|
157
161
|
if (areaCode2 === '07') {
|
|
158
|
-
// Kaohsiung: 07 + 7 digits
|
|
159
|
-
return cleanValue.length === 9 && /^07
|
|
162
|
+
// Kaohsiung: 07 + 7 digits, total 9 digits
|
|
163
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue)
|
|
160
164
|
}
|
|
161
165
|
if (areaCode2 === '08') {
|
|
162
|
-
// Pingtung: 08 + 7 digits
|
|
163
|
-
return cleanValue.length === 9 && /^08
|
|
166
|
+
// Pingtung: 08 + 7 digits, total 9 digits
|
|
167
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue)
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
return false
|
|
@@ -66,45 +66,42 @@ export type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ?
|
|
|
66
66
|
* number patterns.
|
|
67
67
|
*
|
|
68
68
|
* Supported area codes and formats:
|
|
69
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
70
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
71
|
-
* - 037: Miaoli - 6 digits
|
|
72
|
-
* - 04: Taichung, Changhua - 7 digits
|
|
73
|
-
* - 049: Nantou - 7 digits
|
|
69
|
+
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
70
|
+
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
71
|
+
* - 037: Miaoli - 6-7 digits
|
|
72
|
+
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
73
|
+
* - 049: Nantou - 7 digits
|
|
74
74
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
75
75
|
* - 06: Tainan - 7 digits
|
|
76
|
-
* - 07: Kaohsiung - 7 digits
|
|
77
|
-
* - 08: Pingtung - 7 digits
|
|
78
|
-
* - 082: Kinmen - 6 digits
|
|
79
|
-
* -
|
|
80
|
-
* -
|
|
81
|
-
* - 089: Taitung - 6 digits (2~9+5D)
|
|
76
|
+
* - 07: Kaohsiung - 7 digits
|
|
77
|
+
* - 08: Pingtung - 7 digits
|
|
78
|
+
* - 082: Kinmen - 6 digits
|
|
79
|
+
* - 0836: Matsu - 5 digits
|
|
80
|
+
* - 089: Taitung - 6 digits
|
|
82
81
|
*
|
|
83
82
|
* @example
|
|
84
83
|
* ```typescript
|
|
85
84
|
* validateTaiwanTel("0223456789") // true (Taipei area)
|
|
86
|
-
* validateTaiwanTel("
|
|
85
|
+
* validateTaiwanTel("0423288882") // true (Taichung area, 8 digits)
|
|
87
86
|
* validateTaiwanTel("037234567") // true (Miaoli area)
|
|
88
87
|
* validateTaiwanTel("082234567") // true (Kinmen area)
|
|
89
88
|
* validateTaiwanTel("02-2345-6789") // true (with separators)
|
|
90
|
-
* validateTaiwanTel("0812345678") // false (invalid for 08 area)
|
|
91
89
|
* ```
|
|
92
90
|
*/
|
|
93
91
|
const validateTaiwanTel = (value: string): boolean => {
|
|
94
92
|
// Official Taiwan landline formats according to telecom numbering plan:
|
|
95
|
-
// 02: Taipei, New Taipei, Keelung - 8 digits
|
|
96
|
-
// 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
|
|
97
|
-
// 037: Miaoli - 6 digits
|
|
98
|
-
// 04: Taichung, Changhua - 7 digits
|
|
99
|
-
// 049: Nantou - 7 digits
|
|
93
|
+
// 02: Taipei, New Taipei, Keelung - 8 digits
|
|
94
|
+
// 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
95
|
+
// 037: Miaoli - 6-7 digits
|
|
96
|
+
// 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
97
|
+
// 049: Nantou - 7 digits
|
|
100
98
|
// 05: Yunlin, Chiayi - 7 digits
|
|
101
99
|
// 06: Tainan - 7 digits
|
|
102
|
-
// 07: Kaohsiung - 7 digits
|
|
103
|
-
// 08: Pingtung - 7 digits
|
|
104
|
-
// 082: Kinmen - 6 digits
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
// 089: Taitung - 6 digits (2~9+5D)
|
|
100
|
+
// 07: Kaohsiung - 7 digits
|
|
101
|
+
// 08: Pingtung - 7 digits
|
|
102
|
+
// 082: Kinmen - 6 digits
|
|
103
|
+
// 0836: Matsu - 5 digits
|
|
104
|
+
// 089: Taitung - 6 digits
|
|
108
105
|
|
|
109
106
|
// Remove common separators for validation
|
|
110
107
|
const cleanValue = value.replace(/[-\s]/g, "")
|
|
@@ -116,53 +113,60 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
116
113
|
|
|
117
114
|
// Check 4-digit area codes first
|
|
118
115
|
const areaCode4 = cleanValue.substring(0, 4)
|
|
119
|
-
if (areaCode4 === "0826") {
|
|
120
|
-
// Wuqiu: 0826 + 5 digits (6+4D), total 9 digits
|
|
121
|
-
return cleanValue.length === 9 && /^0826[6]\d{4}$/.test(cleanValue)
|
|
122
|
-
}
|
|
123
116
|
if (areaCode4 === "0836") {
|
|
124
|
-
// Matsu: 0836 + 5 digits
|
|
125
|
-
return cleanValue.length === 9 && /^0836
|
|
117
|
+
// Matsu: 0836 + 5 digits, total 9 digits
|
|
118
|
+
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue)
|
|
126
119
|
}
|
|
127
120
|
|
|
128
121
|
// Check 3-digit area codes
|
|
129
122
|
const areaCode3 = cleanValue.substring(0, 3)
|
|
130
123
|
if (areaCode3 === "037") {
|
|
131
|
-
// Miaoli: 037 + 6 digits
|
|
132
|
-
return cleanValue.length === 9 && /^037
|
|
124
|
+
// Miaoli: 037 + 6-7 digits, total 9-10 digits
|
|
125
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037\d{6,7}$/.test(cleanValue)
|
|
133
126
|
}
|
|
134
127
|
if (areaCode3 === "049") {
|
|
135
|
-
// Nantou: 049 + 7 digits
|
|
136
|
-
return cleanValue.length === 10 && /^049
|
|
128
|
+
// Nantou: 049 + 7 digits, total 10 digits
|
|
129
|
+
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue)
|
|
137
130
|
}
|
|
138
131
|
if (areaCode3 === "082") {
|
|
139
|
-
// Kinmen: 082 + 6 digits
|
|
140
|
-
return cleanValue.length === 9 && /^082
|
|
132
|
+
// Kinmen: 082 + 6 digits, total 9 digits
|
|
133
|
+
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue)
|
|
141
134
|
}
|
|
142
135
|
if (areaCode3 === "089") {
|
|
143
|
-
// Taitung: 089 + 6 digits
|
|
144
|
-
return cleanValue.length === 9 && /^089
|
|
136
|
+
// Taitung: 089 + 6 digits, total 9 digits
|
|
137
|
+
return cleanValue.length === 9 && /^089\d{6}$/.test(cleanValue)
|
|
145
138
|
}
|
|
146
139
|
|
|
147
140
|
// Check 2-digit area codes
|
|
148
141
|
const areaCode2 = cleanValue.substring(0, 2)
|
|
149
142
|
|
|
150
143
|
if (areaCode2 === "02") {
|
|
151
|
-
// Taipei, New Taipei, Keelung: 02 + 8 digits
|
|
152
|
-
return cleanValue.length === 10 && /^02
|
|
144
|
+
// Taipei, New Taipei, Keelung: 02 + 8 digits, total 10 digits
|
|
145
|
+
return cleanValue.length === 10 && /^02\d{8}$/.test(cleanValue)
|
|
146
|
+
}
|
|
147
|
+
if (areaCode2 === "03") {
|
|
148
|
+
// Taoyuan, Hsinchu, Yilan, Hualien: 03 + 7-8 digits, total 9-10 digits
|
|
149
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue)
|
|
150
|
+
}
|
|
151
|
+
if (areaCode2 === "04") {
|
|
152
|
+
// Taichung, Changhua, Nantou: 04 + 7-8 digits, total 9-10 digits
|
|
153
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^04\d{7,8}$/.test(cleanValue)
|
|
154
|
+
}
|
|
155
|
+
if (areaCode2 === "05") {
|
|
156
|
+
// Yunlin, Chiayi: 05 + 7 digits, total 9 digits
|
|
157
|
+
return cleanValue.length === 9 && /^05\d{7}$/.test(cleanValue)
|
|
153
158
|
}
|
|
154
|
-
if (
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
return cleanValue.length === 9
|
|
159
|
+
if (areaCode2 === "06") {
|
|
160
|
+
// Tainan: 06 + 7 digits, total 9 digits
|
|
161
|
+
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue)
|
|
158
162
|
}
|
|
159
163
|
if (areaCode2 === "07") {
|
|
160
|
-
// Kaohsiung: 07 + 7 digits
|
|
161
|
-
return cleanValue.length === 9 && /^07
|
|
164
|
+
// Kaohsiung: 07 + 7 digits, total 9 digits
|
|
165
|
+
return cleanValue.length === 9 && /^07\d{7}$/.test(cleanValue)
|
|
162
166
|
}
|
|
163
167
|
if (areaCode2 === "08") {
|
|
164
|
-
// Pingtung: 08 + 7 digits
|
|
165
|
-
return cleanValue.length === 9 && /^08
|
|
168
|
+
// Pingtung: 08 + 7 digits, total 9 digits
|
|
169
|
+
return cleanValue.length === 9 && /^08\d{7}$/.test(cleanValue)
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
return false
|