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; }
To check the length of a string, a simple approach is to test against a regular expression that starts at the very beginning with a ^ and includes every character until the end by finishing with a $.
You can use this regex /^[ A-Za-z0-9_@./#&+-]*$/. To know more about regex ,watch this videos. You can use this regex /^[ A-Za-z0-9_@./#&+-]*$/.
You will use the given regular expression to validate user input to allow only alphanumeric characters. Alphanumeric characters are all the alphabets and numbers, i.e., letters A–Z, a–z, and digits 0–9.
add {3,5}
to your expression which means length between 3 to 5
/^([a-zA-Z0-9_-]){3,5}$/
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