AlphaNumerical Directives
This only allows the alphabets and numbers in the input box. use this directive to block other than alphabets, and numbers in this functionalities
Save these directives and name it as allowalphanumericOnly
@HostListener('keyup', ['$event']) onKeyUp(event) {
let value = this. eleRef.nativeElement.value;
value = this. functionCall(value);
this. eleRef.nativeElement.value = value;
}
@HostListener('paste', ['$event']) onPaste(event) {
this. eleRef.nativeElement.value =
this. functionCall(_.replace(this. eleRef.nativeElement.value, /[^a-zA-Z0-9 ]/g, ''));
}
functionCall(value) {
value = _.replace(value, /^\s/g, '');
value = _.replace(value, /[^a-zA-Z0-9 ]/g, '');
return value;
}
0 Comments