How to only allow text in angular 9 ?

In angular template:

(keypress)="allowOnlyText"

In angular component:

allowOnlyText(event): boolean{
	const charCode = (event.which) ? event.which : event.keyCode;
    if (charCode > 90 && charCode < 97 ) {
      return false;
    }
	
	if(charCode < 65 || charCode > 122){
	return false;
	}	
    return true;
}

 221 total views,  50 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.