I need a regular expression that validate for a number with length 4, 5, 6
I used ^[0-9]{4}
to validate for a number of 4, but I do not know how to include validation for 5 and 6.
The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.
It's because of the \w+ where \w+ match one or more alphanumeric characters. \w+ matches digits as well.
Regular expression to allow numbers like +111 123 456 789: ^(\\+\\d{1,3}( )?)?(\\d{3}[ ]?){2}\\d{3}$
Try this:
^[0-9]{4,6}$
{4,6}
= between 4 and 6 characters, inclusive.
[0-9]{4,6}
can be shortened to \d{4,6}
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