I am working on an angular project, and I am trying to ensure that an input field only accepts positive integers between 1 and 28, however the regex I have tried is not marking the form field as invalid when letters are entered.
Here is my code:
setDateRegex = /^[0-9]*$/;
. . .
scheduleSetDaysBefore: [null, [Validators.max(28), Validators.min(1), Validators.pattern(this.setDateRegex)]],
I have also tried the following regular expressions, and none of them are working.
/^[0-9]+$/
/^[0-9]+(\.?[0-9]+)?$/
And a few others I cannot remember.
EDIT
I just wanted to add, I have already achieved something similar by using a Valdidator.pattern()
to check that an email has been entered in an acceptable format, as well as various length validators.