diff --git a/Contraints/RegExConstraint.vb b/Contraints/RegExConstraint.vb new file mode 100644 index 0000000..e569a24 --- /dev/null +++ b/Contraints/RegExConstraint.vb @@ -0,0 +1,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 + + ''' + ''' 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. + ''' + 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 diff --git a/DatabaseObjects.vbproj b/DatabaseObjects.vbproj index 307a3f6..81466e1 100755 --- a/DatabaseObjects.vbproj +++ b/DatabaseObjects.vbproj @@ -114,6 +114,7 @@ +