0

I have a one input field and it will accept 8 numbers with dot and i have to restrict special character under that. Please provide regexp or any other way to achieve this. I am checking below code on keypress:

isNumberKey(evt, val) {
const charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode !== 8) {
  if (val.length !== undefined) {
    if (val.length > 7) {
      return false;
    }
  }
  if (charCode === 190 || charCode === 110) {
    if (!val.includes('.')) {
      this.keyInputFlag = true;
      return true;
    }
    return false;
  } else if (charCode >= 48 && charCode <= 57
    || (charCode >= 96 && charCode <= 105)) {
    this.keyInputFlag = true;
    return true;
  }
  return false;
}
if (charCode === 8) {
  this.keyInputFlag = true;
  return true;
}
return false;

}

Rahul Pawar
  • 159
  • 1
  • 13

0 Answers0