regex for alphanumeric word, must be 6 characters long

MVCNewbzter picture MVCNewbzter · Nov 15, 2008 · Viewed 16.2k times · Source

What is the regex for a alpha numeric word, at least 6 characters long (but at most 50).

Answer

chroder picture chroder · Nov 15, 2008
/[a-zA-Z0-9]{6,50}/

You can use word boundaries at the beginning/end (\b) if you want to actually match a word within text.

/\b[a-zA-Z0-9]{6,50}\b/