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!

3
  • Besides, escape the dot. Commented Mar 7, 2019 at 21:48
  • Awesome. Tried searching for this, but couldn't track it down. Thanks so much. Commented Mar 7, 2019 at 21:49
  • what was your fix @rob Commented Apr 11, 2022 at 9:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.