Skip to content

Commit

Permalink
Liuboff/add one more constant and remove redundant property
Browse files Browse the repository at this point in the history
  • Loading branch information
Liubov Zatsepina committed Dec 2, 2024
1 parent bd15772 commit 6a7774f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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 } from 'shared/constants/regex-constants';
import { SEARCHBAR_REGEX_VALID } from 'shared/constants/regex-constants';
import { SEARCHBAR_REGEX_REPLACE } from 'shared/constants/regex-constants';

@Component({
selector: 'app-searchbar',
Expand All @@ -25,10 +26,9 @@ export class SearchbarComponent implements OnInit, OnDestroy {
private navigationPaths$: Observable<Navigation[]>;
@Select(FilterState.searchQuery)
private searchQuery$: Observable<string>;
public searchRegex: RegExp = SEARCHBAR_REGEX;

public filteredResults: string[];
public searchValueFormControl = new FormControl('', [Validators.maxLength(256), Validators.pattern(this.searchRegex)]);
public searchValueFormControl = new FormControl('', [Validators.maxLength(256), Validators.pattern(SEARCHBAR_REGEX_VALID)]);

private previousResults: string[] = this.getPreviousResults();
private isResultPage = false;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class SearchbarComponent implements OnInit, OnDestroy {
}

public handleInvalidCharacter(value: string): void {
const validValue = value?.replace(/[^A-Za-zА-Яа-яІіЇїЄєҐґ0-9`.,№"'\s]/g, '');
const validValue = value?.replace(SEARCHBAR_REGEX_REPLACE, '');
if (validValue !== value) {
this.searchValueFormControl.setValue(validValue);
this.invalidCharacterDetected.emit();
Expand Down
7 changes: 5 additions & 2 deletions src/app/shared/constants/regex-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ 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
export const SEARCHBAR_REGEX: RegExp = /^[A-Za-zА-Яа-яІіЇїЄєҐґ0-9`.,№"'\\s]*$/;
// 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;

0 comments on commit 6a7774f

Please sign in to comment.