Regular Expression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to validate a textbox in which the user enters the following -
"smtp.servername.com or .net or .org or .com.uk etc... and I cannot. I have
tried. The string is in the form xxxxx.xxxxxxx.xxx or xxxx.xxxxx.xxx.xx. Does
anyone have any idea how to validate this string.
VB2005
 
Ben said:
I am trying to validate a textbox in which the user enters the following -
"smtp.servername.com or .net or .org or .com.uk etc... and I cannot. I
have
tried. The string is in the form xxxxx.xxxxxxx.xxx or xxxx.xxxxx.xxx.xx.
Does
anyone have any idea how to validate this string.
VB2005

What if it is smtp.servername.bc.ca or similar? You don't get those?
 
Ben said:
I am trying to validate a textbox in which the user enters the following -
"smtp.servername.com or .net or .org or .com.uk etc... and I cannot. I have
tried. The string is in the form xxxxx.xxxxxxx.xxx or xxxx.xxxxx.xxx.xx. Does
anyone have any idea how to validate this string.
VB2005

Use something like:

"(\w+\.){2,3}\w+"
 
Use something like:

"(\w+\.){2,3}\w+"

Don't forget hyphen...

([-\w]+\.)+[-\w]+


OK, I spose that should really be...
(\w+([-\w]+)*\w\.)+(\w+([-\w]+)*\w)

That middle '+' should be a star if we want to match on the local
domain, though.

Beyond just ensuring it's a valid DNS hostname, I'm not sure if the OP
really has additional constraints or if the question is just poorly
worded, so I'm assuming we're just looking for well-formed names.
 
Thanks to all of you. and Thanks for the website with the tutorials.
Thanks

david said:
Use something like:

"(\w+\.){2,3}\w+"

Don't forget hyphen...

([-\w]+\.)+[-\w]+


OK, I spose that should really be...
(\w+([-\w]+)*\w\.)+(\w+([-\w]+)*\w)

That middle '+' should be a star if we want to match on the local
domain, though.

Beyond just ensuring it's a valid DNS hostname, I'm not sure if the OP
really has additional constraints or if the question is just poorly
worded, so I'm assuming we're just looking for well-formed names.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top