import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({
    selector: '[AlphaNumeric]'
})
export class AlphaNumericDirective {
    // private regex = /^((\\+91-?)|0)?[0-9]{1,10}$/;

    constructor(private _el: ElementRef) { }

    @HostListener('input', ['$event']) onInputChange(event: { stopPropagation: () => void; }) {
        const initalValue = this._el.nativeElement.value;

        this._el.nativeElement.value = initalValue.replace(/[^a-zA-Z\s.]*/g, '');
        if (initalValue !== this._el.nativeElement.value) {
            event.stopPropagation();
        }
    }
}