1

I have an element being passed in, some of which have a precision field. I'm putting together a validation pattern to make sure users enter a number with the correct precision, however there's a bit of a trick to it. I can't just inject the number of decimal places I want using Angular. This works for 3 decimal places:

if (element.precision) {
    runElement.validationPattern = /^\d*.\d{3}$/;
}

however, some elements have a precision of 2, some of 1, etc.

I'd like to do something like this:

if (element.precision) {
    runElement.validationPattern = /^\d*.\d{' + element.precision + '}$/;
}

Anybody with the Angular and Regex knowledge out there on how to do this? Thanks!

Rob
  • 897
  • 3
  • 8
  • 22

0 Answers0