Following usernames should be allowed:
Foo-Bar
Foobar
Fooo_123
Foob123_1
Foo-bar-123
Following user names should not be allowed:
_Foobar_
F-o-o-b-a-r
-Foobar-
_-Foobar-_
This means: The string is allowed to be 3 to 20 characters long. There is only one dash or underscore allowed every three characters. Not at the beginning and not and the end. You are only allowed to use at most 2 of a dash or underscore, a maximum of 3 numbers, but a minimum of 3 letters.
This is the Regexp I've done so far, but I already failed at allowing dashes at the front and end:
/^[^\-_][a-zA-Z0-9]{3,20}[^\-_]$/
Thanks in advance!