.net - Validation regular expression for windows domain user name -


i dug through lots of google matches can't find correct, working regular expression validate domain\username.
have little knowledge regex , know nothing rules of domain , user name restrictions/rules.

thanks,
péter

you check presence of backslash or forward-slash in username.

string usernameentered = @"sm/asd"; var domainstylelogin = new regex(@"^.*(\\|/)"); var match = domainstylelogin.match(usernameentered); if (!match.success) {     //does not contain backslash } 

edit

if want check username or domain entered, use :

var validusernameordomain = new regex(@"^[a-za-z0-9\\\._-]{7,}$"); 

this validate :

  • match upper , lower case letters, numbers 0-9, underscore, hyphen, backslash, , period.
  • string not less 7 characters (minimum of 3 characters username , domain, plus domain slash)

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -