0

I have validation at my typeScript. I can validate between 0 and 9 successfully which does not allow me to press except numerical characters. That's fine but the problem is in the second digit it gives me error. The validation below is only find for the first digit. How I can make my validation to available for all inputs not only first digit?

'input2': [this.FormInput.input2,[ Validators.required, Validators.pattern('[0-9]'), ] 
2
  • You could write a (regex) pattern that doesn't explicitly match only a single digit. Commented Apr 3, 2017 at 20:01
  • With latest version of angular you can write like this Validators.pattern(/\d*/) that allows 0 or more digits and Validators.pattern(/\d+/) to allow one or more digits Commented Apr 3, 2017 at 20:12

1 Answer 1

1

You can use the regular expression [0-9]+ to match one or more digits

'input2': [this.FormInput.input2,[ Validators.required, Validators.pattern('[0-9]+'), ] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.