I have a text box. I want to make the textbox accept float value when dataType=3
while keypress
event. I am able to achieve this for number, but trying to do the same for float. But not able to achieve this. While inserting float point ('dot') it showing me alert message. Is there any way to do it? While i
This is i tried
<input class="form-control"
type="text"
[(ngModel)]="fieldValue"
(ngModelChange)="onInputTextChange()"
(keypress)="checkInputType($event)" />
checkInputType(event): boolean {
if (this.dataType === 2) {
const charCode = event.which ? event.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
this.alertService.error("Can't enter any character");
return false;
}
}
if (this.dataType === 3) {
console.log('e')
//const charCode = event.which ? event.which : event.keyCode;
if ((event.which != 46) && (event.which < 48 || event.which > 57) || (event.which == 46)) {
this.alertService.error("Can't enter any character");
return false;
}
}
return true;
}