There are a couple of issues that need to be addressed.
- You should use
{5,15}
instead of {4,15}+
- Make sure to include the character
/
Your code can be revised as follows:
var reg3 = new RegExp('^[a-z0-9?/-]{5,15}$', 'i'); // The 'i' flag eliminates the need for A-Z
alert(reg3.test("a1?-A7="));
Update
Let's not confuse what can be done with what MUST be done; let's focus on the main point I am trying to convey.
The section {4,15}+
in /^([a-zA-Z0-9?-]){4,15}+$/
should actually be {5,15}
, and don't forget to include /
; this will make your regular expression:
/^([a-zA-Z0-9?/-]){5,15}$/
which CAN also be written as:
/^[a-z0-9?/-]{5,15}$/i // The 'i' flag eliminates the need for A-Z
I hope everyone is comfortable using the /i
flag as well.