0

I have the following code that works. I need to have this format: 9999999.9999 or -9999999.9999

So 7 numbers before the decimal and 4 after decimal and the ability to have an hyphen as well.

I believe this will allow hyphens: (?!^-). I am not sure how to make it all work. Here is my code.

var state = undefined;

$('.numeric-decimal-114').on('input', function(event) {             
  var val = $(this).val();        
  var regex1 = new RegExp(/^(\d{1,7}|\d{0,7}\.\d{0,4})$/g);
  if (!regex1.test(val) && val !== "") {
    $(this).val(state);
    return;
  }
  state = val;
});
Tretiak
  • 59
  • 1
  • 5

0 Answers0