new to regex

P

Peter Proost

Hi group, can the following be done by using a regex, I want a textbox only
to contain numbers or . / + - ^ , but I've never used a regex before so I
don't know how to go about it. Could I for example check if the typed
character is in a given regex. Maybe this is a stupid question, I don't now.

grtz Peter
 
O

One Handed Man \( OHM - Terry Burns \)

I think if you look at the help it will tell you. I hardly ever use regex,
but the help clearly explains how to use it

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
P

Peter Proost

I'll check it out, thnx, nice signature BTW :)

One Handed Man ( OHM - Terry Burns ) said:
I think if you look at the help it will tell you. I hardly ever use regex,
but the help clearly explains how to use it

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
J

Jay B. Harlow [MVP - Outlook]

Peter,
Do you want a well formed value in the textbox or just those characters?

Here is a sample RegEx used in the Validating event of the TextBox for jsut
those characters (not well formed).

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Const pattern As String = "^[\d./+-^,]+$"
Static theRegex As New System.Text.RegularExpressions.Regex(pattern,
System.Text.RegularExpressions.RegexOptions.Compiled)
If theRegex.IsMatch(TextBox1.Text) Then
Me.ErrorProvider1.SetError(TextBox1, "")
Else
Me.ErrorProvider1.SetError(TextBox1, "Invalid characters")
e.Cancel = True
End If
End Sub

The following sites provide a wealth of information on regular expressions.

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/d...l/cpconRegularExpressionsLanguageElements.asp


Hope this helps
Jay
 

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

Top