Skip to content

Commit

Permalink
Added a RegExConstraint for validating constraints using regular expr…
Browse files Browse the repository at this point in the history
…essions. Closes #15.
  • Loading branch information
hisystems committed Mar 10, 2012
1 parent 4fab384 commit 34ec24a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions 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

''' <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
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -114,6 +114,7 @@
<Compile Include="Attributes\SubsetAttribute.vb" />
<Compile Include="Attributes\TableAttribute.vb" />
<Compile Include="Attributes\TableJoinAttribute.vb" />
<Compile Include="Contraints\RegExConstraint.vb" />
<Compile Include="Contraints\DateIsTodayOrFutureForNewObjectConstraint.vb" />
<Compile Include="Contraints\NumberIsMaximumOrLesserConstraint.vb" />
<Compile Include="Contraints\StringMaxLengthConstraint.vb" />
Expand Down

0 comments on commit 34ec24a

Please sign in to comment.