Using Regex

  • Thread starter Thread starter larry
  • Start date Start date
L

larry

Hi,
I need to use "regex" to validate user input into a text
box.

I'm having trouble adding the 'regex' class to my
project. Essentially, I haven't learned how to add it.
can someone tell me how this is done? must I
use "imports"?
If so, please tell me how.
thanks
 
Yes, you need to add this import: Imports System.Text.RegularExpressions


Example------> Dim reg as New Regex("[aeiou]\d")

("[aeiou]\d") this means a vowel followed by a digit.
 
It's located in the System.Text.RegularExpressions namespace.

You never have to use "Imports" -- that just gives you to a convenient
shortcut in your code, so you don't have to use fully-qualified class names.
For example, you can either type:

Dim rx as New System.Text.RegularExpressions.Regex

or you can use

Imports System.Text.RegularExpressions
....
Dim rx as New Regex

If you use a class many times in your code, it will save you some typing and
keep your code a little shorter. Nothing more.

In the future, you can find the full name of a class by using the Index in
the MSDN help. For example, typing in "Regex" into the "Look For" box will
direct you to the Regex help page, which tells you that "Regex" is located
in System.Text.RegularExpressions.
 
Back
Top