I've found a lot questions on StackOverflow about how to do this, but it's just not working for me.
var username = "abcdefg";
var min_length = 3;
var max_length = 24;
var regex = new RegExp('^[\w.-]{' + min_length + ',' + max_length + '}$');
if (regex.test(username))
document.getElementById('status').innerHTML = 'match';
else
document.getElementById('status').innerHTML = 'no match';
I've also tried with slashes before and after:
new RegExp('/^[\w.-]{' + min_length + ',' + max_length + '}$/')
And I've also tried with double quotes instead of single quotes (not sure if regex treats single quotes as reserved or something).
If I remove the quotes and put in numbers for the variables it works fine:
new RegExp(/^[\w.-]{3,24}$/)
jsFiddle: http://jsfiddle.net/88ef3/
/in your pattern in the jsfiddle