Skip to content

Commit 6d3707f

Browse files
committed
fix: fix float zero formatting
1 parent a70bb45 commit 6d3707f

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

src/lib/kit/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"label_error-space-start": "Value must not start with a space",
4242
"label_error-zero-start": "Value must not start with a zero",
4343
"label_error-dot-end": "Value must not end with a dot",
44+
"label_error-invalid-zero-format": "Invalid zero value format",
4445
"label_delete": "Delete",
4546
"button_cancel": "Close",
4647
"button-upload_file": "Upload file",

src/lib/kit/i18n/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"label_error-space-start": "Значение не должно начинаться с пробела",
4242
"label_error-zero-start": "Значение не должно начинаться с нуля",
4343
"label_error-dot-end": "Значение не должно заканчиваться точкой",
44+
"label_error-invalid-zero-format": "Неверный формат значения нуля",
4445
"label_delete": "Удалить",
4546
"button_cancel": "Закрыть",
4647
"button-upload_file": "Загрузить файл",

src/lib/kit/validators/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const getErrorMessages = (): ErrorMessagesType => ({
3030
SPACE_END: i18n('label_error-space-end'),
3131
DOT_END: i18n('label_error-dot-end'),
3232
ZERO_START: i18n('label_error-zero-start'),
33+
INVALID_ZERO_FORMAT: i18n('label_error-invalid-zero-format'),
3334
});
3435

3536
export let ErrorMessages: ErrorMessagesType = getErrorMessages();

src/lib/kit/validators/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface ErrorMessagesType {
1313
SPACE_END: string;
1414
DOT_END: string;
1515
ZERO_START: string;
16+
INVALID_ZERO_FORMAT: string;
1617
}

src/lib/kit/validators/validators.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export interface GetNumberValidatorParams extends CommonValidatorParams {
8484
ignoreIntCheck?: boolean;
8585
ignoreDotEnd?: boolean;
8686
ignoreZeroStart?: boolean;
87+
ignoreInvalidZeroFormat?: boolean;
8788
}
8889

8990
export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
@@ -97,6 +98,7 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
9798
ignoreIntCheck,
9899
ignoreDotEnd,
99100
ignoreZeroStart,
101+
ignoreInvalidZeroFormat,
100102
customErrorMessages,
101103
} = params;
102104

@@ -136,6 +138,14 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
136138
) {
137139
return errorMessages.ZERO_START;
138140
}
141+
142+
if (
143+
!ignoreInvalidZeroFormat &&
144+
stringValue.trim().length > 1 &&
145+
Number(stringValue.trim()) === 0
146+
) {
147+
return errorMessages.INVALID_ZERO_FORMAT;
148+
}
139149
}
140150

141151
if (

0 commit comments

Comments
 (0)