Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get FQDN using Regular expression.. help!

Status
Not open for further replies.

Joespower

IS-IT--Management
Jul 3, 2007
7
US
Okay guys, this is my first post, but I've used info from these forums in the past and you guys kick ass!

Here is my question:

I have a logon script that maps drives and printers, and I want make certain that the passed server references are FQDNs. So, I need a way to take a string and see if its a FQDN based on these rules:

1) The whole string can't be more than 255 characters.
2) Individual labels can't be more than 63 characters. (labels are the stuff between the ".'s")
3) Each label must begin with a letter.
4) Each label must end with a letter or number
5) The letters in between in a label can be numbers, letters, or hyphens (no underscores).
6) Case doesn't matter.
7) Can't contain any whitespace.
8) Can be no trailing "." at the end of the whole string (this is debatable, but its what we do internally).

Now I'm no newbie to regular expressions. I have used them a bunch when scripting in a Unix environment. But, I'm having a hard time with the vbscript syntax. I decided to start with the label portion of the RegExp, and what I have so far works as long as the label has more than 1 letter. Having a single letter label is valid for FQDNs, so I have to find a way to fix this...

So, I set up my RegExp like this:

Dim regExp
Set regExp = New RegExp
With regExp
.Pattern = "(((^[a-zA-Z])([a-zA-Z0-9]|-)*)+)(\w$){1,63}"
.IgnoreCase = True
.Global = True
End With


I then use the Test method to test out my passed server name. As I said, everything is fine until I reduce it to a single letter name, but then it breaks down...

Any help would be great!
 
to:eek:p
You don't expect me (or anybody else for that matter) to give twice the same advice? Just remove "as xxx" in the dim appeared in the vb version to make it vbs operable in your case. Furthermore, you don't concile what advice you have received in any other forum(s) under the umbrella of tek-tips brandname. You disclose it.
 
Thanks for your reply PHV, I've been looking at that document for a while but I'm still having problems.

....


Agreed tsuji, I should have made a compilation of what I recieved from the other forum, but I was in a hurry when I made this post. I will go back and do that shortly....

In the mean time, I would mention that your solution to remove the "as xxx" statements in not sufficient. I have tried that, and it doesn't work. Everything I posted in the other forum about type mismatching still applies (remember, I thought I was supposed to be testing this in VBscript the whole time, rather than VB, so I still have the same problems)....

I'll post what I've tried later...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top