Rules Operator's
General Properties
• $required: This operator specifies that the field is required, meaning it cannot be null or undefined.
For number Type (K extends number)
(K extends number)1. $enum: Specifies a list of valid values for the number field. The field must match one of the values from the array.
2. $multipleOf: The number must be a multiple of the specified value.
3. $positive: The number must be positive, greater than 0.
4. $negative: The number must be negative, less than 0.
5. $integer: The number must be an integer (no decimal values).
6. $float: The number must be a floating-point value (has decimal places).
7. $even: The number must be even (divisible by 2).
8. $odd: The number must be odd (not divisible by 2).
9. $prime: The number must be a prime number (greater than 1 and only divisible by 1 and itself).
10. $perfect: The number must be a perfect number (equal to the sum of its proper divisors, excluding itself).
11. $fibonacci: The number must be a Fibonacci number (a sequence where each number is the sum of the two preceding ones).
12. $powerOfTwo: The number must be a power of 2 (e.g., 1, 2, 4, 8, etc.).
13. $powerOfTen: The number must be a power of 10 (e.g., 10, 100, 1000, etc.).
14. $powerOf: The number must be a power of the specified base number.
15. $range: Specifies the valid range for the number with a minimum ($min) and maximum ($max) value.
16. $greaterThan: The number must be greater than the specified value.
17. $lessThan: The number must be less than the specified value.
18. $greaterThanOrEqual: The number must be greater than or equal to the specified value.
19. $lessThanOrEqual: The number must be less than or equal to the specified value.
20. $finite: The number must be a finite value (not Infinity or NaN).
21. $infinite: The number must be infinite (i.e., Infinity or -Infinity).
22. $palindrome: The number must be a palindrome (it reads the same forward and backward).
23. $harshad: The number must be a Harshad number (divisible by the sum of its digits).
24. $epochTime: The number must be a valid epoch timestamp (milliseconds since January 1, 1970).
25. $angle: Specifies that the number must be a valid angle in either radians or degrees, with a specified range ($min, $max).
26. $logicalOr: This allows for logical OR between multiple rules. The field must satisfy at least one of the rules in the provided array.
27. $logicalNot: This allows for logical NOT, meaning the field must not satisfy the rule defined.
28. $custom: This allows you to define a custom validation function. The field value is passed to this function, and the function should return true or false.
For string Type (K extends string)
(K extends string)1. $minLength: Specifies the minimum length that the string must have.
2. $maxLength: Specifies the maximum length that the string can have.
3. $exactLength: Specifies the exact length that the string must have.
4. $alphaNumeric: The string must be alphanumeric, containing only letters and numbers.
5. $contains: The string must contain the specified substring.
6. $startsWith: The string must start with the specified substring.
7. $endsWith: The string must end with the specified substring.
8. $exclude: The string must not contain the specified substring.
9. $noWhitespace: The string must not contain any whitespace characters.
10. $onlySpecialChars: The string must contain only special characters (no alphanumeric characters).
11. $noSpecialChars: The string must not contain any special characters.
12. $alpha: The string must contain only alphabetic characters.
13. $numeric: The string must contain only numeric characters.
14. $locale: The string must be validated according to the specified locale (e.g., language and regional settings).
15. $enum: Specifies a list of valid values for the string field. The field must match one of the values from the array.
16. $match: The string must match the provided regular expression (RegExp).
17. $validEmail: The string must be a valid email address format.
18. $validURL: The string must be a valid URL format.
19. $validIP: The string must be a valid IP address format.
20. $validIPv4: The string must be a valid IPv4 address format.
21. $validIPv6: The string must be a valid IPv6 address format.
22. $validUUID: The string must be a valid UUID (Universally Unique Identifier) format.
23. $validCreditCard: The string must be a valid credit card number format.
24. $custom: Allows defining a custom validation function for the string. The field value is passed to this function, and it should return true or false.
For boolean Type (K extends boolean)
(K extends boolean)1. $mustBeTrue: The boolean field must be true.
2. $mustBeFalse: The boolean field must be false.
Last updated