0

I am using Validators.pattern(/^[1-9][0-9]{0,2}$/) to allow only numbers from 1 to 999 on the number input field.

This regular expression is validating correctly even for -ve values if selected from input range arrows(have set min=1, max=999 on <input>). But when I type number explicitly its accepting 099, 0999, 0990 too and not displaying error. The same pattern when checked in regex101.com says "no match" for inputs starting with 0. Why is the same regex pattern working weirdly in actual code(matching) and regex101.com(not matching)?

3
  • You need to make sure the input's type="text" Commented Oct 21, 2021 at 20:02
  • @WiktorStribiżew thanks, but the input field should be of number type in order to enter numbers only and to have a range up & down arrows? Commented Oct 21, 2021 at 20:22
  • I linked the question to a possible solution. Please try and if it does not work for you, update the question. Commented Oct 22, 2021 at 12:54

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.