public static IRuleOut <string> Email(this IRuleIn <string> @this, EmailValidationMode mode = EmailValidationMode.ComplexRegex) { if (!Enum.IsDefined(typeof(EmailValidationMode), mode)) { throw new ArgumentException("Invalid EmailValidationMode value", nameof(mode)); } if (mode == EmailValidationMode.DataAnnotationsCompatible) { return(@this.RuleTemplate(IsEmailValidAccordingToDataAnnotations, MessageKey.Texts.Email)); } return(@this.RuleTemplate(IsEmailValidAccordingToRegex, MessageKey.Texts.Email)); }
public static IRuleOut <string> HasCharacter(this IRuleIn <string> @this) { return(@this.RuleTemplate( value => value.Length > 0, "Must have at least one character!" )); }
public static IRuleOut <TCollection> MinCollectionSize <TCollection, TItem>(this IRuleIn <TCollection> @this, int min) where TCollection : IEnumerable <TItem> { ThrowHelper.BelowZero(min, nameof(min)); return(@this.RuleTemplate(m => m.Count() >= min, MessageKey.Collections.MinCollectionSize, Arg.Number(nameof(min), min))); }
public static IRuleOut <TCollection> ExactCollectionSize <TCollection, TItem>(this IRuleIn <TCollection> @this, int size) where TCollection : IEnumerable <TItem> { ThrowHelper.BelowZero(size, nameof(size)); return(@this.RuleTemplate(m => m.Count() == size, MessageKey.Collections.ExactCollectionSize, Arg.Number(nameof(size), size))); }
public static IRuleOut <string> ExactLinesCount(this IRuleIn <string> @this, int count) { return(@this.RuleTemplate( value => value.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length == count, "Must contain exactly {count} lines", Arg.Number("count", count) )); }
public static IRuleOut <string> HasCharacter( this IRuleIn <string> @this, char character, int count = 1) { return(@this.RuleTemplate( value => value.Count(c => c == character) == count, "Text.HasCharacter", Arg.Text(nameof(character), character), Arg.Number(nameof(count), count) )); }
public static IRuleOut <string> LengthBetween(this IRuleIn <string> @this, int min, int max) { ThrowHelper.BelowZero(min, nameof(min)); ThrowHelper.BelowZero(max, nameof(max)); ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max)); return(@this.RuleTemplate( v => { var squashedLength = v.Replace(Environment.NewLine, " ").Length; return squashedLength >= min && squashedLength <= max; }, MessageKey.Texts.LengthBetween, Arg.Number(nameof(min), min), Arg.Number(nameof(max), max))); }
public static IRuleOut <TCollection> CollectionSizeBetween <TCollection, TItem>(this IRuleIn <TCollection> @this, int min, int max) where TCollection : IEnumerable <TItem> { ThrowHelper.BelowZero(min, nameof(min)); ThrowHelper.BelowZero(max, nameof(max)); ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max)); return(@this.RuleTemplate( m => { var count = m.Count(); return count >= min && count <= max; }, MessageKey.Collections.CollectionSizeBetween, Arg.Number(nameof(min), min), Arg.Number(nameof(max), max))); }
public static IRuleOut <TimeSpan> EqualTo(this IRuleIn <TimeSpan> @this, TimeSpan value) { return(@this.RuleTemplate(m => m == value, MessageKey.TimeSpanType.EqualTo, Arg.Time(nameof(value), value))); }
public static IRuleOut <ushort> NonPositive(this IRuleIn <ushort> @this) { return(@this.RuleTemplate(m => m <= 0, MessageKey.Numbers.NonPositive)); }
public static IRuleOut <ushort?> NotEqualTo(this IRuleIn <ushort?> @this, ushort value) { return(@this.RuleTemplate(m => m.Value != value, MessageKey.Numbers.NotEqualTo, Arg.Number(nameof(value), value))); }
public static IRuleOut <short?> BetweenOrEqualTo(this IRuleIn <short?> @this, short min, short max) { ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max)); return(@this.RuleTemplate(m => m.Value >= min && m.Value <= max, MessageKey.Numbers.BetweenOrEqualTo, Arg.Number(nameof(min), min), Arg.Number(nameof(max), max))); }
public static IRuleOut <TimeSpan?> GreaterThanOrEqualTo(this IRuleIn <TimeSpan?> @this, TimeSpan min) { return(@this.RuleTemplate(m => m.Value >= min, MessageKey.TimeSpanType.GreaterThanOrEqualTo, Arg.Time(nameof(min), min))); }
public static IRuleOut <short> LessThan(this IRuleIn <short> @this, short max) { return(@this.RuleTemplate(m => m < max, MessageKey.Numbers.LessThan, Arg.Number(nameof(max), max))); }
public static IRuleOut <short> Between(this IRuleIn <short> @this, short min, short max) { ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max)); return(@this.RuleTemplate(m => m > min && m < max, MessageKey.Numbers.Between, Arg.Number(nameof(min), min), Arg.Number(nameof(max), max))); }
public static IRuleOut <short> GreaterThan(this IRuleIn <short> @this, short min) { return(@this.RuleTemplate(m => m > min, MessageKey.Numbers.GreaterThan, Arg.Number(nameof(min), min))); }
public static IRuleOut <short> Negative(this IRuleIn <short> @this) { return(@this.RuleTemplate(m => m < 0, MessageKey.Numbers.Negative)); }
public static IRuleOut <TimeSpan> Between(this IRuleIn <TimeSpan> @this, TimeSpan min, TimeSpan max) { ThrowHelper.InvalidRange(min.Ticks, nameof(min), max.Ticks, nameof(max)); return(@this.RuleTemplate(m => m > min && m < max, MessageKey.TimeSpanType.Between, Arg.Time(nameof(min), min), Arg.Time(nameof(max), max))); }
public static IRuleOut <TimeSpan?> LessThanOrEqualTo(this IRuleIn <TimeSpan?> @this, TimeSpan max) { return(@this.RuleTemplate(m => m.Value <= max, MessageKey.TimeSpanType.LessThanOrEqualTo, Arg.Time(nameof(max), max))); }
public static IRuleOut <TimeSpan> LessThan(this IRuleIn <TimeSpan> @this, TimeSpan max) { return(@this.RuleTemplate(m => m < max, MessageKey.TimeSpanType.LessThan, Arg.Time(nameof(max), max))); }
public static IRuleOut <short?> NonNegative(this IRuleIn <short?> @this) { return(@this.RuleTemplate(m => m.Value >= 0, MessageKey.Numbers.NonNegative)); }
public static IRuleOut <TimeSpan?> BetweenOrEqualTo(this IRuleIn <TimeSpan?> @this, TimeSpan min, TimeSpan max) { ThrowHelper.InvalidRange(min.Ticks, nameof(min), max.Ticks, nameof(max)); return(@this.RuleTemplate(m => m.Value >= min && m.Value <= max, MessageKey.TimeSpanType.BetweenOrEqualTo, Arg.Time(nameof(min), min), Arg.Time(nameof(max), max))); }
public static IRuleOut <short?> GreaterThanOrEqualTo(this IRuleIn <short?> @this, short min) { return(@this.RuleTemplate(m => m.Value >= min, MessageKey.Numbers.GreaterThanOrEqualTo, Arg.Number(nameof(min), min))); }
public static IRuleOut <TimeSpan> NonZero(this IRuleIn <TimeSpan> @this) { return(@this.RuleTemplate(m => m.Ticks != 0, MessageKey.TimeSpanType.NonZero)); }
public static IRuleOut <short?> LessThanOrEqualTo(this IRuleIn <short?> @this, short max) { return(@this.RuleTemplate(m => m.Value <= max, MessageKey.Numbers.LessThanOrEqualTo, Arg.Number(nameof(max), max))); }
public static IRuleOut <char?> NotEqualToIgnoreCase(this IRuleIn <char?> @this, char value) { return(@this.RuleTemplate(v => string.Compare(v.Value.ToString(CultureInfo.InvariantCulture).ToUpperInvariant(), value.ToString(CultureInfo.InvariantCulture).ToUpperInvariant(), StringComparison.Ordinal) != 0, MessageKey.CharType.NotEqualToIgnoreCase, Arg.Text(nameof(value), value))); }
public static IRuleOut <short> EqualTo(this IRuleIn <short> @this, short value) { return(@this.RuleTemplate(m => m == value, MessageKey.Numbers.EqualTo, Arg.Number(nameof(value), value))); }
public static IRuleOut <ushort?> NonZero(this IRuleIn <ushort?> @this) { return(@this.RuleTemplate(m => m.Value != 0, MessageKey.Numbers.NonZero)); }
public static IRuleOut <short> NonZero(this IRuleIn <short> @this) { return(@this.RuleTemplate(m => m != 0, MessageKey.Numbers.NonZero)); }
public static IRuleOut <ushort?> Positive(this IRuleIn <ushort?> @this) { return(@this.RuleTemplate(m => m.Value > 0, MessageKey.Numbers.Positive)); }