I'm going to check the username via both JavaScript then PHP.
The username can contain English letters, numbers and one hyphen (-).
The username cannot be started with hyphen (-).
The username cannot be finished with hyphen (-).
The username cannot be started with numbers.
The username cannot contain more than one hyphen (-).
The username cannot be shorter than 6 and longer than 20.
abc123 is correct.
abc-123 is correct.
ab12 is wrong: username is shorter than 6 character.
-abc123 is wrong: username is started with hyphen.
abc123- is wrong: username is finished with hyphen.
ab-12-c3 is wrong: username contains more than one hyphen.
123abc is wrong: username is started with numbers.