Advertisement
ElliottE4

Untitled

Apr 7th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.21 KB | None | 0 0
  1. Imports System.Text.RegularExpressions
  2. Public Class Validation
  3.  
  4.     'class is used in order to call specific validation check functions anywhere in the code
  5.  
  6.     Public Function lengthCheck(ByVal ValidationInput As String, ByVal CharLength As Integer, ByVal ErrorPrompt As String, ByVal parameters As String) As Boolean
  7.  
  8.         If parameters = "Max" Then 'if the character limit is the maximum length that can be input
  9.  
  10.             If ValidationInput.Length <= CharLength Then 'if the input string's length is less than the maximum length of characters then:
  11.  
  12.                 Return True 'return true if the length is shorter or equal to the maximum length of characters
  13.  
  14.             Else
  15.  
  16.                 'If the input string has more charaters than the maximum, then a message box will be shown:
  17.                 MsgBox(ErrorPrompt & " - Your input has too many characters and exceeds the limit, please correct your input to be shorter than(" & CharLength & ") characters.")
  18.  
  19.                 Return False 'Return false to show that there was an error
  20.  
  21.             End If
  22.  
  23.         ElseIf parameters = "Min" Then 'if the character limit is the minimum length that can be input
  24.  
  25.             If ValidationInput.Length >= CharLength Then 'if the input string's length is more than the minimum length of characters then:
  26.  
  27.                 Return True 'return true if the length is bigger or equal to the minimum length of characters
  28.  
  29.             Else
  30.  
  31.                 'If the input string has less charaters than the minimum, then a message box will be shown:
  32.                 MsgBox(ErrorPrompt & " - Your input has too little characters and isn't long enough, please correct your input to be longer than(" & CharLength & ") characters.")
  33.  
  34.                 Return False 'Return false to show that there was an error
  35.  
  36.             End If
  37.  
  38.         ElseIf parameters = "Limit" Then 'if the character limit the only length that can be input
  39.  
  40.             If ValidationInput.Length = CharLength Then 'if the input string's length the same as the set parameter then:
  41.  
  42.                 Return True 'return true if the length matches
  43.  
  44.             Else
  45.  
  46.                 'If the input string has more or less charaters than the paramter, then a message box will be shown:
  47.                 MsgBox(ErrorPrompt & " - Your input has doesn't have the correct number of characters, please correct your input to be (" & CharLength & ") characters.")
  48.  
  49.                 Return False 'Return false to show that there was an error
  50.  
  51.             End If
  52.  
  53.         Else
  54.  
  55.             MsgBox("No length parameters specified")
  56.             Return False
  57.  
  58.         End If
  59.  
  60.     End Function
  61.  
  62.     Public Function presenceCheck(ByVal validationInput As String) As Boolean
  63.  
  64.         'presence check checks if there is any data input into the textboxes
  65.  
  66.         If validationInput = "" Then 'checks if the input has no data stored in it
  67.  
  68.             Return False 'if there isn't any data, the function will return a false output to show that it failed the presence check
  69.  
  70.         Else
  71.             Return True 'if there is data, the function will return a true output to show that it passed the presence check
  72.  
  73.         End If
  74.  
  75.     End Function
  76.  
  77.  
  78. End Class
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement