I am trying to add regex to an input field in my angular app. The input field belongs to an HTML set which does not make use of a Form. The regex is to check that the input field is not empty. Is this possible to do? I would like to add it in my validateName function if possible.
Here is my code
HTML
<div>
<div class="ui-g">
<div class="tab-container">
<div class="ui-g-12 ui-md-12">
<strong style="padding-left:12px;">Template Name</strong>
</div>
<div class="ui-g-12 ui-md-12 ">
<div class="input-container">
<label for="jobTitle">Template name*</label>
<input id="jobTitle" type="text" [disabled]="mode == 'view'" [(ngModel)]="templateName" size="100" (keyup)="validateName()">
</div>
<p class="error" *ngIf="!isValid">
* An offer template with this name already exists.
</p>
</div>
</div>
</div>
TS
validateName() {
const regexBlankInput = "^\\s+$";
if(this.templateName != '' ) {
const found = this.usersService.allTemplates.some(x => x.name.toLowerCase() == this.templateName.toLowerCase());
if ((found) || (this.templateName == regexBlankInput)) {
this.isValid = false;
} else{
this.isValid = true;
}
}
}