## Recommended Posts

I am looking for a regular expression for "Domain\UserName"...so essentially string "Text1\Text2" should return as valid. Minor condition is "text1" should have a max length of 8.Thanks.

##### Share on other sites

[A-Za-z0-9-_]{1,8}\\[A-Za-z0-9-_]+

This says

one to eighth alphanumeric characters or a "-" or "_", followed by a "\", followed by one or more alphanumeric characters or a "-" or "_"
If it doesn't work (as I'm a little uncertain about the "-" and "_"), try this as well:
([A-Za-z0-9]|\-|\_){1,8}\\([A-Za-z0-9]|\-|\_)+

Just curious, we are talking about NetBIOS domain names, right?

Edited by boen_robot
##### Share on other sites

Thanks for your reply. By the way, the regular expression you gave me doesn't seem to work properly.If the first string is longer than 8 characters, it still returns true.Also, I am only want to use alpha characters (no Numberic and no Special characters). I tried something like

([A-Za-z]){1,8}\\([A-Za-z])+

and it doesnt' work as well.Thanks again for your help. I appreciate it.

[A-Za-z0-9-_]{1,8}\\[A-Za-z0-9-_]+

This saysIf it doesn't work (as I'm a little uncertain about the "-" and "_"), try this as well:

([A-Za-z0-9]|\-|\_){1,8}\\([A-Za-z0-9]|\-|\_)+

Just curious, we are talking about NetBIOS domain names, right?

##### Share on other sites

Considering the fact we're talking about JavaScript, I have to ask... are you sure you've written the string correctly? You need to also escape the "\" in it, like so:

##### Share on other sites

Thank you so much JustSomeGuy I appreciate your help.

##### Share on other sites

Hey no problem. If you check post 4 you'll see that boen_robot wrote the same pattern in his test script, with the start and end.