-2

I want pass variable instead of number. I want to limit input based on my variable value.

if (isNaN(value) || value.match(/^\d+\.?\d{0,3}$/) === null

this is my expresssion, i want to pass variable "decimal". But i am not able to pass it.

const decimal=column.validations.decimalPlaces

I am trying to write like this if (isNaN(value) || value.match(/^\d+\.?\d{0,decimal}$/) === null but its not working . how can i pass this decimal variable like this

R. Richards
  • 24,603
  • 10
  • 64
  • 64
aashu1807
  • 203
  • 3
  • 14
  • not sure what about using template literal like this `if (isNaN(value) || value.match(/^\d+\.?\d{0,`${decimal}`}$/) === null` ; NOTE it is like "if (isNaN(value) || value.match(/^\d+\.?\d{0,${backtick${decimal}backtick}$/)===null" – micronyks Jul 31 '20 at 11:23

1 Answers1

0

I would escape characters if regex is string:

value.match(`^\\d+\\.?\\d{0,${decimal}}$`) === null
gonzalo
  • 377
  • 2
  • 9