Javascript – Regular expression for number with length of 4, 5 or 6

javascriptregex

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.

Best Answer

Try this:

^[0-9]{4,6}$

{4,6} = between 4 and 6 characters, inclusive.