Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a RegExConstraint for validating constraints using regular expr…
…essions. Closes #15.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters