diff --git a/src/app/shared/components/filters-list/searchbar/searchbar.component.ts b/src/app/shared/components/filters-list/searchbar/searchbar.component.ts index 792c5de4c0..0973cce52b 100644 --- a/src/app/shared/components/filters-list/searchbar/searchbar.component.ts +++ b/src/app/shared/components/filters-list/searchbar/searchbar.component.ts @@ -10,6 +10,8 @@ import { Navigation } from 'shared/models/navigation.model'; import { SetSearchQueryValue } from 'shared/store/filter.actions'; import { FilterState } from 'shared/store/filter.state'; import { NavigationState } from 'shared/store/navigation.state'; +import { SEARCHBAR_REGEX_VALID } from 'shared/constants/regex-constants'; +import { SEARCHBAR_REGEX_REPLACE } from 'shared/constants/regex-constants'; @Component({ selector: 'app-searchbar', @@ -26,7 +28,7 @@ export class SearchbarComponent implements OnInit, OnDestroy { private searchQuery$: Observable; public filteredResults: string[]; - public searchValueFormControl = new FormControl('', [Validators.maxLength(256), Validators.pattern('^[A-Za-zА-Яа-я0-9`.,№"\']*$')]); + public searchValueFormControl = new FormControl('', [Validators.maxLength(256), Validators.pattern(SEARCHBAR_REGEX_VALID)]); private previousResults: string[] = this.getPreviousResults(); private isResultPage = false; @@ -85,7 +87,7 @@ export class SearchbarComponent implements OnInit, OnDestroy { } public handleInvalidCharacter(value: string): void { - const validValue = value?.replace(/[^A-Za-zА-Яа-я0-9`.,№"']/g, ''); + const validValue = value?.replace(SEARCHBAR_REGEX_REPLACE, ''); if (validValue !== value) { this.searchValueFormControl.setValue(validValue); this.invalidCharacterDetected.emit(); diff --git a/src/app/shared/constants/regex-constants.ts b/src/app/shared/constants/regex-constants.ts index 9ceb93484c..37f7bc60c8 100644 --- a/src/app/shared/constants/regex-constants.ts +++ b/src/app/shared/constants/regex-constants.ts @@ -36,3 +36,9 @@ export const SECTION_NAME_REGEX: RegExp = /^(?!`)(?!\^)(?!_)(?!\[)(?!])(?!\\)[А // Regex for checking if string has a letter export const MUST_CONTAIN_LETTERS: RegExp = /[a-zA-ZА-ЯЄІЇҐа-яґєії]/; + +// Regex for searchbar validation +export const SEARCHBAR_REGEX_VALID: RegExp = /^[A-Za-zА-Яа-яІіЇїЄєҐґ0-9`.,№"'\\s]*$/; + +// Regex for searchbar replace invalid characters +export const SEARCHBAR_REGEX_REPLACE: RegExp = /[^A-Za-zА-Яа-яІіЇїЄєҐґ0-9`.,№"'\s]/g;