feat: add region code to car number (#54) #58

Merged
primakov merged 1 commits from feature/car-number-region-code into main 2025-01-12 10:12:43 +03:00
2 changed files with 4 additions and 4 deletions

View File

@ -15,7 +15,7 @@ export const CarNumberInput = forwardRef<HTMLInputElement, InputProps>(
// @ts-ignore // @ts-ignore
onChange?.(formattedValue); onChange?.(formattedValue);
}} }}
maxLength={8} maxLength={12}
/> />
); );
}, },

View File

@ -3,11 +3,11 @@ const VALID_LETTER = 'а|в|е|к|м|н|о|р|с|т|у|х';
const invalidCharsRe = new RegExp(`[^(${VALID_LETTER})0-9]`, 'gi'); const invalidCharsRe = new RegExp(`[^(${VALID_LETTER})0-9]`, 'gi');
const cleanValue = (value: string) => value.replace(invalidCharsRe, ''); const cleanValue = (value: string) => value.replace(invalidCharsRe, '');
const validCarNumberInputRe = new RegExp(`^([${VALID_LETTER}]{1}|$)((?:[0-9]|$)(?:[0-9]|$)(?:[0-9]|$))([${VALID_LETTER}]{1,2}|$)$`, 'gi'); const validCarNumberInputRe = new RegExp(`^([${VALID_LETTER}]{1}|$)((?:[0-9]|$)(?:[0-9]|$)(?:[0-9]|$))([${VALID_LETTER}]{1,2}|$)((?:[0-9]|$)(?:[0-9]|$)(?:[0-9]|$))$`, 'gi');
const isValidInput = (cleanedValue: string) => validCarNumberInputRe.test(cleanedValue); const isValidInput = (cleanedValue: string) => validCarNumberInputRe.test(cleanedValue);
const formatAsCarNumber = (cleanedValue: string) => { const formatAsCarNumber = (cleanedValue: string) => {
return cleanedValue.replace(validCarNumberInputRe, (_, p1, p2, p3) => [p1, p2, p3].join(' ')).toUpperCase(); return cleanedValue.replace(validCarNumberInputRe, (_, p1, p2, p3, p4) => [p1, p2, p3, p4].join(' ')).toUpperCase();
}; };
const getWithoutLastChar = (value: string) => value.substring(0, value.length - 1); const getWithoutLastChar = (value: string) => value.substring(0, value.length - 1);
@ -25,7 +25,7 @@ export const handleInputChange = (value: string | undefined | null) => {
return getWithoutLastChar(value).trim(); return getWithoutLastChar(value).trim();
}; };
const validCarNumberRe = new RegExp(`^[${VALID_LETTER}][0-9]{3}[${VALID_LETTER}]{2}$`, 'i'); const validCarNumberRe = new RegExp(`^[${VALID_LETTER}][0-9]{3}[${VALID_LETTER}]{2}[0-9]{2,3}$`, 'i');
export const isValidCarNumber = (value: string) => { export const isValidCarNumber = (value: string) => {
const cleanedValue = cleanValue(value); const cleanedValue = cleanValue(value);