File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed
Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 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" ,
45+ "label_error-zero-end" : " Value must not end with a zero" ,
4446 "label_delete" : " Delete" ,
4547 "button_cancel" : " Close" ,
4648 "button-upload_file" : " Upload file" ,
Original file line number Diff line number Diff line change 4141 "label_error-space-start" : " Значение не должно начинаться с пробела" ,
4242 "label_error-zero-start" : " Значение не должно начинаться с нуля" ,
4343 "label_error-dot-end" : " Значение не должно заканчиваться точкой" ,
44+ "label_error-invalid-zero-format" : " Неверный формат значения нуля" ,
45+ "label_error-zero-end" : " Значение не должно заканчиваться нулем" ,
4446 "label_delete" : " Удалить" ,
4547 "button_cancel" : " Закрыть" ,
4648 "button-upload_file" : " Загрузить файл" ,
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ 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' ) ,
34+ ZERO_END : i18n ( 'label_error-zero-end' ) ,
3335} ) ;
3436
3537export let ErrorMessages : ErrorMessagesType = getErrorMessages ( ) ;
Original file line number Diff line number Diff line change @@ -13,4 +13,6 @@ export interface ErrorMessagesType {
1313 SPACE_END : string ;
1414 DOT_END : string ;
1515 ZERO_START : string ;
16+ INVALID_ZERO_FORMAT : string ;
17+ ZERO_END : string ;
1618}
Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ export interface GetNumberValidatorParams extends CommonValidatorParams {
8484 ignoreIntCheck ?: boolean ;
8585 ignoreDotEnd ?: boolean ;
8686 ignoreZeroStart ?: boolean ;
87+ ignoreInvalidZeroFormat ?: boolean ;
88+ ignoreZeroEnd ?: boolean ;
8789}
8890
8991export const getNumberValidator = ( params : GetNumberValidatorParams = { } ) => {
@@ -97,6 +99,8 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
9799 ignoreIntCheck,
98100 ignoreDotEnd,
99101 ignoreZeroStart,
102+ ignoreInvalidZeroFormat,
103+ ignoreZeroEnd,
100104 customErrorMessages,
101105 } = params ;
102106
@@ -136,6 +140,22 @@ export const getNumberValidator = (params: GetNumberValidatorParams = {}) => {
136140 ) {
137141 return errorMessages . ZERO_START ;
138142 }
143+
144+ if (
145+ ! ignoreInvalidZeroFormat &&
146+ stringValue . trim ( ) . length > 1 &&
147+ Number ( stringValue . trim ( ) ) === 0
148+ ) {
149+ return errorMessages . INVALID_ZERO_FORMAT ;
150+ }
151+
152+ if (
153+ ! ignoreZeroEnd &&
154+ ! isInt ( stringValue ) &&
155+ stringValue [ stringValue . length - 1 ] === '0'
156+ ) {
157+ return errorMessages . ZERO_END ;
158+ }
139159 }
140160
141161 if (
You can’t perform that action at this time.
0 commit comments