Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Frontend into Shapoval/BackendAvailabilityCheck
  • Loading branch information
DimaShapoval committed Dec 2, 2024
2 parents de3f184 + 02a5cf8 commit 53a072c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -26,7 +28,7 @@ export class SearchbarComponent implements OnInit, OnDestroy {
private searchQuery$: Observable<string>;

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;
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/app/shared/constants/regex-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 53a072c

Please sign in to comment.