I’m trying to write up a regex for a validation JavaScript, that allows the user to input 4-9 numbers (as the string length), but the user should also be able to leave the field blank.
The 4-9 numbers part is easy: ^[0-9]{4,9}$, but I’m struggling on the “not required” part.
I’ve tried ^[0-9]{4,9}|[0-9]{0}$ but that doesn’t work at all.
Simply make your existing pattern optional: