This question has already been answered:
You need to set a regular expression for a range of numbers from 1 to 32. If the number is larger or smaller, you need to return false.
This question has already been answered:
You need to set a regular expression for a range of numbers from 1 to 32. If the number is larger or smaller, you need to return false.
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
To check that a value is in a certain range, it is better to bring it to a number and then check.
var v = parseInt(value); if(v>=1 && v=<32) return true; return false; If you really want to use a regular expression, you can use the following
/^(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32)$/ /^([1-2]?[\d]|3[0-2])$/ :) - user207618^([1-9]|[1-2][\d]|3[0-2])$ - user207618 /^([1-9]|[1-2][\d]|3[0-2])$/ [1-9] - numbers from 1 to 9| - OR[1-2][\d] - numbers from 10 to 29| - OR3[0-2] - numbers from 30 to 32
/^([1-2]?[1-9]|[1-3][0-2])$/ [1-2]?[1-9] - numbers from 1 to 9, numbers from 11 to 19, numbers from 21 to 29| - OR[1-3][0-2] - numbers from 10 to 12, numbers from 20 to 22, numbers from 30 to 32
\d metacharacter be wrapped in parentheses? My example: \b([1-9]|[1-2]\d|3[0-2])\b - demonstration . - Sasha Chernykh32 is the same power of two, you can check the bits:
32 100000 31 011111 30 011110 .. 2 000010 1 000001 The number minus 1 should be from 0 to 31: from 00000 to 11111 .
if( ((x - 1) & 0x1F) === (x - 1)) { // OK } else { // NOT OK } (x - 1) , suddenly becomes a number - SergiksSource: https://ru.stackoverflow.com/questions/522335/
All Articles