Tuesday, 30 June 2020

Allow number's only in input text Angular-8

HTML:
<input type="text" (input)="onTextboxChangeValidate($event)">

TS(Component type script):
onTextboxChangeValidate(eventEvent) {
    var inputData = (<HTMLInputElement>event.target).value;
    //replace more than one dot
    var extractedFte = inputData.replace(/[^0-9.]/g'').replace('.''')
    .replace(/\./g'').replace('x''.');

    //Extract number Values
    extractedFte = extractedFte.replace(/^(\d+)\d*$/"$1");

    //Reasign to same control
    (<HTMLInputElement>event.target).value = extractedFte;
  }

No comments:

Post a Comment