I have modified an existing plunker to meet your specific requirements.
This directive is a sample of what it may look like:
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
selector: '[OnlyLowerCaseAlphabets]'
})
export class OnlyLowerCaseAlphabets {
constructor(private el: ElementRef) { }
@Input() OnlyLowerCaseAlphabets: boolean;
private regex: RegExp = new RegExp( /^[a-z]+$/);
@HostListener('keydown', [ '$event' ])
onKeyDown(event: KeyboardEvent) {
let current: string = this.el.nativeElement.value;
let next: string = current.concat(event.key);
if (next && !String(next).match(this.regex)) {
event.preventDefault();
}
}
}
You can view the modified plunker here:
https://embed.plnkr.co/M6gYgSxeuw7wW6rfoWEZ/