Class ReglaIdValido
  Inherits ValidationRule
  Private _idMin As Double
  Private _idMax As Double

  Public Property IdMin() As Double
    Get
      Return _idMin
    End Get
    Set(value As Double)
      _idMin = value
    End Set
  End Property

  Public Property IdMax() As Double
    Get
      Return _idMax
    End Get
    Set(value As Double)
      _idMax = value
    End Set
  End Property

  Public Overrides Function Validate(value As Object, cultureInfo As System.Globalization.CultureInfo) As ValidationResult
    Dim id As Integer
    If Not Integer.TryParse(value.ToString(), id) Then
      Return New ValidationResult(False, "Identificador no válido.")
    End If

    If id < IdMin OrElse id > IdMax Then
      Return New ValidationResult(False, String.Format("Valor fuera del rango {0} a {1}", IdMin, IdMax))
    End If

    Return ValidationResult.ValidResult
  End Function
End Class
