You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.2 KiB

Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Data.SqlDbType
Imports System.Data.SqlClient
Public Class clsValidator
Dim m_result As String
Property Resultmessage As String
Get
Return m_result
End Get
Set(value As String)
m_result = value
End Set
End Property
Dim Connectionstring As String
Dim ds As New DataSet
Sub New()
Me.Connectionstring = Globals.sConnectionString
End Sub
Sub Get_Validatordata()
Dim scmCmdToExecute As SqlCommand = New SqlCommand()
Dim dtToReturn As DataTable = New DataTable()
Dim sdaAdapter As SqlDataAdapter = New SqlDataAdapter(scmCmdToExecute)
scmCmdToExecute.CommandText = "select * from URLValidate where aktiv=1 order by nreintrag"
scmCmdToExecute.CommandType = CommandType.Text
scmCmdToExecute.Connection = conn.scoDBConnection
Try
sdaAdapter.Fill(dtToReturn)
ds.Tables.Clear()
ds.Tables.Add(dtToReturn)
Catch ex As Exception
MsgBox("URL-Validator:" + ex.Message)
Finally
scmCmdToExecute.Dispose()
sdaAdapter.Dispose()
End Try
End Sub
Public Function VerifyString(ByVal inputstring As String) As Boolean
If Trim(inputstring) = "" Then
Return True
Exit Function
End If
Get_Validatordata()
Me.Resultmessage = ""
For Each r As DataRow In ds.Tables(0).Rows
If r.Item("Regex") = True Then
Dim regex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(r.Item("Regel"))
Dim match As Match = regex.Match(inputstring)
If r.Item("zwingend") And match.Success = False Then
Me.Resultmessage = r.Item("Meldung")
Return False
End If
If r.Item("nicht_erlaubt") And match.Success = True Then
Me.Resultmessage = r.Item("Meldung")
Return False
End If
regex = Nothing
Else
Dim sp As String()
sp = UCase(r.Item("Regel")).ToString.Split("|")
Dim treffer As Integer = 0
If r.Item("zwingend") = True Then
For i As Integer = 0 To sp.Count - 1
If sp(i) <> "|" Then If UCase(inputstring).IndexOf(sp(i)) > -1 Then treffer = treffer + 1
Next
If treffer = 0 Then
Me.Resultmessage = r.Item("meldung")
Return False
End If
End If
If r.Item("nicht_erlaubt") = True Then
For i As Integer = 0 To sp.Count - 1
If sp(i) <> "|" Then If UCase(inputstring).IndexOf(sp(i)) > -1 Then treffer = treffer + 1
Next
If treffer > 0 Then
Me.Resultmessage = r.Item("meldung")
Return False
End If
End If
End If
Next
Return True
End Function
End Class