I want to validate the username with below condition
Accept only Characters and NUmbers
Accept " _ " or " . "(either any one)
Here is my code
<input type="text" class="form-control" [maxlength]="50" name="userName" placeholder="User Name"
#userName="ngModel" ngModel [(ngModel)]="UserName" (keypress)="userNameValidation($event)">
userNameValidation(event: any) {
const pattern = /^[a-zA-Z0-9\_\.]+$/
const inputChar = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!pattern.test(inputChar)) {
event.preventDefault();
}
}
Can anybody help me to write the either or condition???