I have a unique collection that appears as follows:
listA = ["Physics","English","Chemistry","Biology","History","Human Values","None"]
The website displays a textArea for users to input data like :-
Hello, I really enjoy studying <<English>>
or
My favorite subject is <<Biology>>, it's the best
If a user enters anything other than what's in the listA between the <<>>, I want to display a validation error message with the remaining content being customizable.
I attempted to use regular expressions and directives but couldn't quite get it right. Please let me know if you need further explanation
This is my current attempt :
checkText(event) {
// const regex = /(?:^|\s)<<(.*?)>>(?:\s|$)/g;
var str = this.editClauseObj.textObj.text;
console.log("str",str);
let name_val = 'Name';
const regex = /^([a-zA-Z]*\s)*[<<name_val>>]*\s*[a-zA-Z\s]*$/g
if (!regex.test(str)) {
this.showError = true;
this.errorMessage = "Please enter a valid value inside <<>>"
console.log("test", this.showError);
} else {
// do something else
this.showError = false;
}
}