NumberRules class abstract final

Factory class for creating number validation rules.

All rules are generic over the number type T (num, int, double) and error type E, so you can use any error type.

Example with num

final priceValidator = Formix.all<num, String>([
  NumberRules.min(0, error: 'Must be non-negative'),
  NumberRules.max(1000000, error: 'Price too high'),
]);

Example with int

final ageValidator = Formix.all<int, String>([
  NumberRules.range(0, 150, error: 'Invalid age'),
]);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

divisibleBy<T extends num, E>(num divisor, {required E error}) Rule<T, E>
Validates that the number is divisible by divisor.
equals<T extends num, E>(T expected, {required E error}) Rule<T, E>
Validates that the number equals expected.
even<E>({required E error}) Rule<int, E>
Validates that the number is even.
greaterThan<T extends num, E>(T threshold, {required E error}) Rule<T, E>
Validates that the number is greater than threshold.
isFinite<T extends num, E>({required E error}) Rule<T, E>
Validates that the number is finite (not infinite or NaN).
isInteger<E>({required E error}) Rule<num, E>
Validates that the number is an integer (no decimal part).
isNotNaN<E>({required E error}) Rule<double, E>
Validates that the number is not NaN.
lessThan<T extends num, E>(T threshold, {required E error}) Rule<T, E>
Validates that the number is less than threshold.
max<T extends num, E>(T max, {required E error}) Rule<T, E>
Validates that the number is at most max.
maxDecimalPlaces<E>(int places, {required E error}) Rule<double, E>
Validates that the number has at most places decimal places.
min<T extends num, E>(T min, {required E error}) Rule<T, E>
Validates that the number is at least min.
negative<T extends num, E>({required E error}) Rule<T, E>
Validates that the number is negative (< 0).
nonNegative<T extends num, E>({required E error}) Rule<T, E>
Validates that the number is non-negative (>= 0).
nonPositive<T extends num, E>({required E error}) Rule<T, E>
Validates that the number is non-positive (<= 0).
notEquals<T extends num, E>(T value, {required E error}) Rule<T, E>
Validates that the number is not equal to value.
odd<E>({required E error}) Rule<int, E>
Validates that the number is odd.
positive<T extends num, E>({required E error}) Rule<T, E>
Validates that the number is positive (> 0).
range<T extends num, E>(T min, T max, {required E error}) Rule<T, E>
Validates that the number is within min and max (inclusive).