Thank you, ksandom. I did it and it works great.
Maybe you know what is the function to check that string '-' is not in the begginning and not in the end of word? I want that users when register an account can use string '-' only in the middle of word, for exapmle,
user-name = OK
my-user-name = OK
but
-username = NOT OK
-user-name = NOT OK
-user-name- = NOT OK
Thank you.