Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add fraction in angular

@Directive({
   selector: '[exampleDirective]'
})
export class TestDirective {

   constructor() {}

   @HostListener('input', ['$event'])
   ngOnChanges(evt: any) {
      const pattern: RegExp = new RegExp(/^[0-9]+.?[0-9]*$/);
      if (!pattern.test(evt.target.value)) {
         evt.srcElement.value = evt.srcElement.value.substring(0, evt.srcElement.value.length - 1); // this will erase the last char that does not match the pattern...
      }
   }
}
Source by pretagteam.com #
 
PREVIOUS NEXT
Tagged: #add #fraction #angular
ADD COMMENT
Topic
Name
9+5 =