Getting a substring of a string in JavaScript
You don't need to over-complicate things. The myuser part will always come at the end of the string, after \\ if it's there.

All you need is this:

username.split("\\").pop();


Even if the username is entered like the third version, the myuser will be returned.