newbie newbie - 1 month ago 9
Javascript Question

JavaScript regex for alphanumeric string with length of 3-5 chars

I need regex for validating alphanumeric String with length of 3-5 chars. I tried following regex found from the web, but it didn't even catch alphanumerics correctly.

var myRegxp = /^([a-zA-Z0-9_-]+)$/;
if(myRegxp.test(value) == false)
{
return false;
}

Answer Source

add {3,5} to your expression which means length between 3 to 5

/^([a-zA-Z0-9_-]){3,5}$/