Skip to content
Snippets Groups Projects
Commit 520024a8 authored by Scott Berg's avatar Scott Berg
Browse files

Fix Regex check on subject input

parent 5b347525
No related branches found
No related tags found
No related merge requests found
Pipeline #33532 passed
...@@ -132,14 +132,16 @@ export class CourseSearchComponent implements OnInit, OnDestroy { ...@@ -132,14 +132,16 @@ export class CourseSearchComponent implements OnInit, OnDestroy {
'subject', 'subject',
) as AbstractControl).valueChanges.subscribe(value => { ) as AbstractControl).valueChanges.subscribe(value => {
// If the subject value is blank, or if the user is typing "all" // If the subject value is blank, or if the user is typing "all"
if (new RegExp('^([Aa]?[Ll]{0,2})$').test(value.trim())) { if (/^(a[l]{0,2})?$/i.test(value.trim())) {
this.filteredSubjects = this.subjects; this.filteredSubjects = this.subjects;
return; return;
} }
this.filteredSubjects = this.subjects.filter(subject => { this.filteredSubjects = this.subjects.filter(subject => {
const search = subject.replace(/\s/g, ''); // Make both comparisons lowercase and remove all whitespace
if (search.toLowerCase().indexOf(value.toLowerCase()) === 0) { const formattedSubject = subject.replace(/\s/g, '').toLowerCase();
const formattedValue = value.replace(/\s/g, '').toLowerCase();
if (formattedSubject.indexOf(formattedValue) === 0) {
return true; return true;
} }
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment