For creating a username format validator the conditions are:
Username may only contain alphanumeric characters or hyphens. This username cannot have multiple consecutive hyphens. The username cannot begin or end with a hyphen. Maximum is 39 characters.
I have found the answer myself, this library might be helpfull - https://github.com/shinnn/github-username-regex