What is needed is that the user enters the month in Number (without using any date controls); where you must validate that it is a positive number and that it accepts 1 to 9 and 0 to 2; only that they do not require month 01 or month 09 to be entered, if not 9 or 1; What I have done so far is this
^[+]?(0[1-9]|1[0-2])
The problem is that this must use the month 01 and that is what the user does not want.
var re = /^[+]?(0[1-9]|1[0-2])/;
console.log(re.test('') + ' No cumple' );
console.log(re.test('1')+ ' No cumple deberia Cumplir');
console.log(re.test('01'));
console.log(re.test('12'));
console.log(re.test('13') + ' No cumple');
console.log(re.test('9') + ' No cumple deberia Cumplir');
Test
/^[+]?(0?[1-9]|1[0-2])$/
I've made the zero optional
0?
, and I've also made the string have to end there$
.I don't know if this last condition works for you, but if I don't put it, it also accepts 13 (in reality it keeps 1, 3 doesn't pass the condition, but when passing part of the text string it considers it valid).
If you do not put
$
, in fact, it will also give you valid: 22, 45, 023, etc.You could achieve it like this:
?
the0
(zero) in the group for months less than10
$
to the end of the regular expression, to validate the entire string[+]?
( personally, I wouldn't know what this is for )demonstration: