Skip to content

CommonBusinessRules

This Object provides Basic Business Rules for use with objects. Centralizes reusable validation constants and rule helpers shared by multiple business objects.

Purpose

  • Centralizes reusable validation constants and rule helpers shared by multiple business objects.

Context

  • Namespace: SAIF.Business
  • Assembly/package: SAIF.Business

Public members

Member Signature Purpose
MIN_REASONABLE_DATE_OFFSET Public Const MIN_REASONABLE_DATE_OFFSET As Integer = -100 Exposes shared constant values.
MAX_REASONABLE_DATE_OFFSET Public Const MAX_REASONABLE_DATE_OFFSET As Integer = 5 Exposes shared constant values.
REGEX_PHONE Public Const REGEX_PHONE As String = "\(?\s*\d{3}\s*[\)\.\-]?\s*\d{3}\S*[\.\-]?\s*\d{4}" Exposes shared constant values.
REGEX_EMAIL Public Const REGEX_EMAIL As String = "^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,5}|[0-9]{1,3})(\]?)$" Exposes shared constant values.
IsTodayOrFutureDate Public Shared Function IsTodayOrFutureDate(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property date is today or later.
IsTTodayOrFutureDate Public Shared Function IsTTodayOrFutureDate(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property date is today or earlier.
IsFutureDate Public Shared Function IsFutureDate(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property date is later than today.
IsTFutureDate Public Shared Function IsTFutureDate(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property date is earlier than today.
TextRequired Public Shared Function TextRequired(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property contains at least one character.
TrimTextRequired Public Shared Function TrimTextRequired(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the trimmed target property contains at least one non-space character.
IsReasonableDate Public Shared Function IsReasonableDate(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Sets the rule message and validates that the target property date falls within the configured reasonable year range.
IsReasonableDate Public Shared Function IsReasonableDate(ByVal inDate As Date, Optional ByVal minDateOffsetYears As Integer = MIN_REASONABLE_DATE_OFFSET, Optional ByVal maxDateOffsetYears As Integer = MAX_REASONABLE_DATE_OFFSET) As Boolean Returns whether the supplied date falls within the configured reasonable year range.
IsValidPhoneNum Public Shared Function IsValidPhoneNum(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property matches the shared phone-number regex.
IsValidEmailAddress Public Shared Function IsValidEmailAddress(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates a nonblank target property against the shared email-address regex.
IsValidRequiredEmailAddress Public Shared Function IsValidRequiredEmailAddress(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property matches the shared email-address regex.
DateRequired Public Shared Function DateRequired(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property is not Date.MinValue or Date.MaxValue.
NonZeroDecimalRequired Public Shared Function NonZeroDecimalRequired(ByVal target As Object, ByVal e As clsRuleArgs) As Boolean Validates that the target property decimal value is not zero.

Behavioral notes

  • Rule methods are exposed as Shared functions so business objects can attach them without instantiating the type.
  • The class validates dates, required text, decimal values, phone numbers, and email addresses using shared constants and regex patterns.

Constraints and usage notes

  • Rule helpers expect targets whose properties can be read through CallByName and clsRuleArgs.
  • Regex-based helpers validate string content but do not transform or normalize the caller input.

Sources

  • Business\SAIF.Business\CommonBusinessRules.vb