Imports System.Text.RegularExpressions
Public Module Test
Public Sub Main()
' Define a regular expression for currency values.
Dim rx As New Regex("^-?\d+(\.\d{2})?$")
' Define some test strings.
Dim tests() As String = {"-42", "19.99", "0.001", "100 USD", _
".34", "0.34", "1,052.21"}
' Check each test string against the regular expression.
For Each test As String In tests
If rx.IsMatch(test) Then
Console.WriteLine("{0} is a currency value.", test)
Else
Console.WriteLine("{0} is not a currency value.", test)
End If
Next
End Sub
End Module
' The example displays the following output to the console:
' -42 is a currency value.
' 19.99 is a currency value.
' 0.001 is not a currency value.
' 100 USD is not a currency value.
' .34 is not a currency value.
' 0.34 is a currency value.
' 1,052.21 is not a currency value.