/
RegExConstraint.vb
54 lines (34 loc) · 1.4 KB
/
RegExConstraint.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
' ___________________________________________________
'
' (c) Hi-Integrity Systems 2012. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'
Option Strict On
Option Explicit On
Imports System.Text.RegularExpressions
Namespace Constraints
''' <summary>
''' Ensures that the associated binding value is a match for the regular expression.
''' Utilises the System.Text.RegularExpressions.RegEx.IsMatch() function to determine whether the value matches.
''' </summary>
Public Class RegExConstraint
Implements IConstraint(Of String)
Private pobjRegularExpression As Regex
Public Sub New(ByVal objRegularExpression As Regex)
If objRegularExpression Is Nothing Then
Throw New ArgumentNullException
End If
pobjRegularExpression = objRegularExpression
End Sub
Public Sub New(ByVal strRegularExpression As String)
Me.New(New Regex(strRegularExpression))
End Sub
Private Function ValueSatisfiesConstraint(value As String) As Boolean Implements IConstraint(Of String).ValueSatisfiesConstraint
Return pobjRegularExpression.IsMatch(value)
End Function
Public Overrides Function ToString() As String
Return pobjRegularExpression.ToString
End Function
End Class
End Namespace