Reputation: 2181
I dug through lots of google matches but I can't find a correct, working regular expression to validate domain\username.
I have too little knowledge about regex and I know nothing about the rules of the domain and user name restrictions/rules.
Thanks,
Péter
Upvotes: 1
Views: 15353
Reputation: 2160
I ended up using
/^[a-zA-Z][a-zA-Z0-9\-\. ]{0,61}[a-zA-Z]\\\w[\w\.\- ]+$/
(based on this SO answer)
Upvotes: 2
Reputation: 3819
You could just check for the presence of the backslash or forward-slash in the username.
string UsernameEntered = @"sm/asd";
var DomainStyleLogin = new Regex(@"^.*(\\|/)");
var match = DomainStyleLogin.Match(UsernameEntered);
if (!match.Success)
{
//Does not contain a backslash
}
EDIT
If you want to check the username or domain entered, you could use something like this :
var ValidUsernameOrDomain = new Regex(@"^[A-Za-z0-9\\\._-]{7,}$");
This will validate for :
Upvotes: 4