I have following now.
regex=^[0-9]{6}$
this is working for starting 0 to 9 and for 6 and 7 digit number.
Please suggest how can i add for 5, 6 and 7 digit numbers.
match(/(\d{5})/g);
\d for single or multiple digit numbers It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range. [1-9][0-9] will match double digit number from 10 to 99.
regex = "[0-9]+"; Match the given string with Regular Expression. In Java, this can be done by using Pattern.
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.
use the range form of the { }
operator
^[0-9]{5,7}$
Range inside of {N,M}
is demarcated with a comma and translates into a string with length between N
and M
inclusive.
This is notably different from the [ ]
operator which is to describe a character group and uses the -
symbol to demarcate its ranges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With