From 34ec24afd612f11058d1e954c41c75490168ce76 Mon Sep 17 00:00:00 2001 From: Toby Wicks Date: Sat, 10 Mar 2012 14:05:14 +1030 Subject: [PATCH] Added a RegExConstraint for validating constraints using regular expressions. Closes #15. --- Contraints/RegExConstraint.vb | 54 +++++++++++++++++++++++++++++++++++ DatabaseObjects.vbproj | 1 + 2 files changed, 55 insertions(+) create mode 100644 Contraints/RegExConstraint.vb 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 @@ +