I want to do a directive of can allow input enter only text and space, or integer, or float. but I get only false, in this 3 ways
<div class="ui-g-10" >
<label for="Id">{{'Nome' | doisPontos}}</label><br>
<div class="ui-inputgroup">
<input appFiltrarTipo type="text" formControlName="Nome" style="text-align: left; width: 450px;" id="Nome" appUppercase [(ngModel)]="secaoForm.value.Nome" [value]="secaoForm.value.Nome" pInputText >
</div>
</div>
I pass how parameter I want preventDefault(), but in this 3 parameters the result is only false
import {Directive, ElementRef, Input} from '@angular/core'
let input = Input
@Directive({
selector: '[appFiltrarTipo]'
})
export class FiltrarTipoDirective {
private readonly REGEX = {
text: '[a-zA-Z ]',
integer: '[0-9]',
float: '[0-9.]'
}
private readonly specialKeys = [ 'Backspace', 'Tab', 'End', 'Home', '-' ];
@input() type: string;
constructor(public el: ElementRef) {
this.el.nativeElement.onkeypress = (evt) => {
if(this.specialKeys.indexOf(evt.key) !== -1) return;
let filter = new RegExp(this.REGEX[this.type])
if(!filter.test(this.el.nativeElement.value)){
event.preventDefault();
}
console.log(filter.test(this.el.nativeElement.value))
};
}
}
filterandthis.el.nativeElement.valuewhat is the output?