Regular expression characters less than 82

I am trying to write a simple regular expression, but I do not know why it does not work.

The user enters 2 digits, for example 01 , 09 , 23 , 55 , up to 82 . After 82 system will fail.

Here is my regex, 2 digits should be less than 82.

 0[1-9]|[1-8][0-9]|8[0-2] 
+4
source share
3 answers

You should have [1-7] for the range 10-79, not [1-8] . Do not forget ^ and $ to indicate the beginning and end of the line:

 ^(0[1-9]|[1-7]\d|8[0-2])$ 
+7
source

Why not distinguish an integer and then just check x < 82 ?

+4
source

Your second part is wrong. It will match from 10 to 89, while you want it to match from 10 to 79 and allow the third part to be processed from 80 to 82.

 0[1-9]|[1-7][0-9]|8[0-2] 
+1
source

Source: https://habr.com/ru/post/1415382/


All Articles