Validator Reference

Numeric Validation Rules

Between
Equals
IsGreaterThan
IsGreaterThanOrEqual
IsLessThan
IsLessThanOrEqual
IsZero

Between

Between(int StartValue, int EndValue, string ErrorMessage)
Between(int StartValue, int EndValue)
Checks that the value is within the provided range.

Equals

Equals(int EqualValue, string ErrorMessage)
Equals(int EqualValue)
Checks that the value is the same as the provided value.

IsGreaterThan

IsGreaterThan(int GreaterThanValue, string ErrorMessage)
IsGreaterThan(int GreaterThanValue)
Checks that the value is greater than the provided value.

IsGreaterThanOrEqual

IsGreaterThanOrEqual(int GreaterThanValue, string ErrorMessage)
IsGreaterThanOrEqual(int GreaterThanValue)
Checks that the value is greater than or equal to the provided value.

IsLessThan

IsLessThan(int LessThanValue, string ErrorMessage)
IsLessThan(int LessThanValue)
Checks that the value is less than the provided value.

IsLessThanOrEqual

IsLessThanOrEqual(int lessThanValue, string ErrorMessage)
IsLessThanOrEqual(int lessThanValue)
Checks that the value is less than or equal to the provided value.

IsZero

IsZero(string ErrorMessage)
IsZero()
Checks that the value is zero.

String Validation Rules

Contains
EndsWith
HasALengthBetween
IsDate
IsDecimal
IsEmail
IsEmpty
IsInteger
IsLength
IsLongerThan
IsShorterThan
IsURL
MatchRegex
StartsWith

Contains

Contains(string CompareValue, string ErrorMessage)
Contains(string CompareValue)
Checks that the string contains the specified CompareValue.

EndsWith

EndsWith(string EndValue, string ErrorMessage)
EndsWith(string EndValue)
Checks that the string ends with EndValue.

HasALengthBetween

HasALengthBetween(int MinLength, int MaxLength, string ErrorMessage)
HasALengthBetween(int MinLength, int MaxLength)
Checks that the length of the string is within the provided minimum and maximum length limits.

IsDate

IsDate(string ErrorMessage)
IsDate()
Checks if the string can be parsed as a date under the current locale.

IsDecimal

IsDecimal(string ErrorMessage)
IsDecimal()
Checks if the string can be parsed as a deciaml under the current locale.

IsEmail

IsEmail(string ErrorMessage)
IsEmail()
Checks that the string is an email address.

IsEmpty

IsEmpty(string ErrorMessage)
IsEmpty()
Checks if the string is empty.

IsInteger

IsInteger(string ErrorMessage)
IsInteger()
Checks if the string can be parsed as an integer.

IsLength

IsLength(int RequiredLength, string ErrorMessage)
IsLength(int RequiredLength)
Checks if the string has the correct length

IsLongerThan

IsLongerThan(int MinLength, string ErrorMessage)
IsLongerThan(int MinLength)
Checks if the string has more characters than the specified minimum.

IsShorterThan

IsShorterThan(int MaxLength, string ErrorMessage)
IsShorterThan(int MaxLength)
Checks that the string has less characters than the provided maximum.

IsURL

IsURL(string ErrorMessage)
IsURL()
Checks that the string is a URL.

MatchRegex

MatchRegex(string RegularExpression, string ErrorMessage)
MatchRegex(string RegularExpression, RegexOptions regexOptions, string ErrorMessage)
Checks that the string matches the supplied regular expression.

StartsWith

StartsWith(string StartValue, string ErrorMessage)
StartsWith(string StartValue)
Checks that the string starts with StartValue.

Date Validation Rules

IsEarlierThan
IsLaterThan
IsNotAFutureDate
IsNotAPastDate
IsNotMinMaxValue

IsEarlierThan

IsEarlierThan(DateTime CheckDateValue, string ErrorMessage)
IsEarlierThan(DateTime CheckDateValue)
Checks that the date is ealier than the provided check date.

IsLaterThan

IsLaterThan(DateTime CheckDateValue, string ErrorMessage)
IsLaterThan(DateTime CheckDateValue)
Checks that the date is later than the provided check date.

IsNotAFutureDate

IsNotAFutureDate(string errorMessage)
IsNotAFutureDate()
Checks that the date provided is not in the future (has a date part that is later than today).

IsNotAPastDate

IsNotAPastDate(string errorMessage)
IsNotAPastDate()
Checks that the date provided is not in the past (has a date part that is not earlier than today).

IsNotMinMaxValue

IsNotMinMaxValue(string ErrorMessage)
IsNotMinMaxValue()
Checks that the date is not DateTime.Min or DateTime.Max.

Boolean Validation Rules

IsFalse
IsTrue

IsFalse

IsFalse(string ErrorMessage)
IsFalse()
Checks if the boolean value is false.

IsTrue

IsTrue(string ErrorMessage)
IsTrue()
Checks if the boolean value is true.

Custom Validation With Predicate Lambdas

All validators provide an Is method that can be supplied with a lambda expression. The lambda takes the value being validated as a parameter and should return true if the value is OK, and false if there is a problem. An error message must always be supplied, since there is no way TNValidate can generate one for you in this case.
Validate.That(Value, "Square")
    .Is(x => (int)Math.Pow(Math.Floor(Math.Sqrt((double)x)), 2) == x, "Must be a square number");

Last edited Jan 14, 2010 at 12:51 PM by jnthn, version 6

Comments

No comments yet.