Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular expression for Windows Domain user name

Last post 06-04-2008, 7:57 PM by Aussie Susan. 19 replies.
Page 2 of 2 (20 items)   < Previous 1 2
Sort Posts: Previous Next
  •  05-14-2008, 2:39 AM 42232 in reply to 42230

    Re: Regular expression for Windows Domain user name

    Deepak_Regex:

     

    I used  @" " ..but didn;t work for me.

     I getting error in line just above the if statment...So it doesn't matter whether we use return _regularExpression.IsMatch(userDomainName);
     or with if statment.

    I used escape character for all "\" ..but it didn;t help me.

    Somebody who know .NET,please try this expression and let me know what is solution for error.

    Thanks,

    The expression is fine, your code is the problem. All the character escapes are just for C# strings, nothing to do with regex in particular. You've typed something incorrectly.  Even if you use @ you still have to escape double quotes in the pattern otherwise C# with think the string ended.  If you don't use the at sign, you have to escape the backslash. Since you didn't post your modified code attempts, I can't see what you are  or are not doing correctly.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  05-15-2008, 1:28 AM 42277 in reply to 42232

    Re: Regular expression for Windows Domain user name

    mash:
    Deepak_Regex:

     

    I used  @" " ..but didn;t work for me.

     I getting error in line just above the if statment...So it doesn't matter whether we use return _regularExpression.IsMatch(userDomainName);
     or with if statment.

    I used escape character for all "\" ..but it didn;t help me.

    Somebody who know .NET,please try this expression and let me know what is solution for error.

    Thanks,

    The expression is fine, your code is the problem. All the character escapes are just for C# strings, nothing to do with regex in particular. You've typed something incorrectly.  Even if you use @ you still have to escape double quotes in the pattern otherwise C# with think the string ended.  If you don't use the at sign, you have to escape the backslash. Since you didn't post your modified code attempts, I can't see what you are  or are not doing correctly.

     

    HI

     this is orginal expression which  works fine when i tested in regex tool

    ^([a-z][a-z0-9.-]+)\\(?![\x20.]+$)([^\\/"[\]:|<>+=;,?*@]+)$

    When i used above expression directly without any modification ,I was getting compile time error bcoz of double quotes C# compiler was thinking as end of string,so I have used one backward slash just before double quotes  and also one backward slash just before the "\"  in subpattern [\\]

     here is code i am using .....

    private const string ValidUserDomainNameRegularExpression = "^([a-z][a-z0-9.-]+)\\(?![\x20.]+$)([^\\/\"[\\]:|<>+=;,?*@]+)$";

    private bool IsValidUserDomainName1(string userDomainName)

    {

    bool isValid = false;

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    bool isValid = false;

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    private bool IsValidUserDomainName1(string userDomainName)

    {

    bool isValid = false;

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    bool isValid = false;

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

  •  05-15-2008, 11:30 AM 42311 in reply to 42277

    Re: Regular expression for Windows Domain user name

    Deepak_Regex:
    mash:
    Deepak_Regex:

     

    I used  @" " ..but didn;t work for me.

     I getting error in line just above the if statment...So it doesn't matter whether we use return _regularExpression.IsMatch(userDomainName);
     or with if statment.

    I used escape character for all "\" ..but it didn;t help me.

    Somebody who know .NET,please try this expression and let me know what is solution for error.

    Thanks,

    The expression is fine, your code is the problem. All the character escapes are just for C# strings, nothing to do with regex in particular. You've typed something incorrectly.  Even if you use @ you still have to escape double quotes in the pattern otherwise C# with think the string ended.  If you don't use the at sign, you have to escape the backslash. Since you didn't post your modified code attempts, I can't see what you are  or are not doing correctly.

     

    HI

     this is orginal expression which  works fine when i tested in regex tool

    ^([a-z][a-z0-9.-]+)\\(?![\x20.]+$)([^\\/"[\]:|<>+=;,?*@]+)$

    When i used above expression directly without any modification ,I was getting compile time error bcoz of double quotes C# compiler was thinking as end of string,so I have used one backward slash just before double quotes  and also one backward slash just before the "\"  in subpattern [\\]

     here is code i am using .....

    private const string ValidUserDomainNameRegularExpression = "^([a-z][a-z0-9.-]+)\\(?![\x20.]+$)([^\\/\"[\\]:|<>+=;,?*@]+)$";

    private bool IsValidUserDomainName1(string userDomainName)

    {

    bool isValid = false;

    _regularExpression = new Regex(ValidUserDomainNameRegularExpression, RegexOptions.IgnorePatternWhitespace);

    if (_regularExpression.IsMatch(userDomainName))

    {

    isValid = true;

    }

     

    return isValid;

    }

     

    I tried using "@" ,but didn;t worked for fine...

    Please let me know what is right solution....

    You only replaced one backslash and left the rest as the were. As I said before for C# you have to escape all the backslashes in a string.  This is C# syntax for strings and has nothing to do with regex in particular.      Take the original pattern and everywhere you see a backslash, irregardless of its purpose, replace it with two backslashes.  If anywhere in your  code's string there is not an even number of consecutive backslashes the regex will function differently in your code  Your code will have twice as many backslashes as your testing tool had. If you put the original pattern in text editor and did a replace all, replacing "\" with "\\"

    If you use the @ preceeding your string you can type it as is, except for the double quote which has to be escaped for C#, not for the regex engine. 

    The double quote has to be escape in either case.  If you use a backslash to escape the double quote for C# it will be a single backslash. You could you two consecutive double quotes to escape instead.

    Personally I always use \x22 in my patterns in place of the double quote character to avoid language syntax errors. http://regexadvice.com/blogs/mash/archive/2005/05/18/934.aspx


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  06-04-2008, 11:21 AM 42891 in reply to 42311

    Re: Regular expression for Windows Domain user name

    Hi,

      Thanks for reply..it is working fine...

    I have one doubt...I want alter exisiting regular expresion if they user specify user domain name in different format.

    Now i have regular expression for  this format - "Domain Name \ User Name" - ^([a-z][a-z0-9.-]+)\\(?![\x20.]+$)([^\\/"[\]:|<>+=;,?*@]+)$

    Now i want regular if they specify in this format  " User Name @ Domain Name "

    Criteria for user name and domain name remain same,which have mentioned earlier in post.( i guess Expression for each domain name part and user name part remain same i guess ..!!!)

    Please help me regarding this.

    thanks,

     

  •  06-04-2008, 7:57 PM 42906 in reply to 42891

    Re: Regular expression for Windows Domain user name

    The simple answer is to make it something like:

     ^(?![\x20.]+$)([^\\/"[\]:|<>+=;,?*@]+)@([a-z][a-z0-9.-]+)$

    All I have done is to take the 'domain name' and 'user name' sub-patterns and swap their order with a '@' in between instead of a '\'.

    However, your question leads me to wonder how much you actually understand how the pattern works. I have no problem with simply giving you an answer but, unless you spend a bit of time studying it and understanding how it works, then you will likely find that it will cause problems in the future when you have to maintain the program that uses it. I would strongly recommend that you try to learn from the questions and examples that are presented in this forum (and other places on the Internet) so that you can save yourself a lot of time and trouble later on.

    Susan 

Page 2 of 2 (20 items)   < Previous 1 2
View as RSS news feed in XML