
April 1st, 2009, 07:29 PM
|
|
|
I am no expert at regex, but I would guess like this
Air coded ~ (VB.NET)
Code:
Imports System.Text
Public Class Form1
Private Function DoesItMatch (ByVal pInput As String, ByVal pEvaluator As String) As Boolean
If RegularExpressions.Regex.IsMatch(pInput, pEvaluator) Then
Return True
Else
Return False
End If
End Function
Private Sub MySub()
'Get the string that we want to evaluate
Dim strInput As String = TextBox1.Text
'Is it a number 0 through 9?
Dim boolIsZeroThroughNine As Boolean = DoesItMatch(strInput, "\b[0-9]\b") 'Note: In VB.NET the beginning & end of a string are denoted with a "\b", where in most other RegEx expressions, it is "^" & "$" respectively.
If boolIsZeroThroughNine = True Then
MessageBox.Show("It is 0 through 9")
Else
MessageBox.Show("It is NOT 0 through 9")
End If
'Or, just check if it is numeric
Dim boolIsNumeric As Boolean = DoesItMatch(strInput, "\b\d\b") 'I believe the "\d" stands for decimal
If boolIsNumeric = True Then
MessageBox.Show("It is numeric")
Else
MessageBox.Show("It is NOT numeric")
End If
End Sub
End Class
|