The problem is that | has lower priority than ^ and $ , so your pattern means ^[1-9] or 0[1-9] or 1[0-9] or 2[0]$ : only single digits are limited ^ , and only 20 limited to $ .
You can either repeat ^ and $ in each branch of the strip, or wrap the strip in (?:...) to create an unrecoverable subexpression:
/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/ /^(?:[1-9]|0[1-9]|1[0-9]|20)$/
(I also allowed changing [0] to 0 )
ruakh
source share