1

I want to add validation for an Integer, that its minimum digit value is 5 and maximum digit value is 20

For Integer I have set following validations

Integer(min_occurs=1, gt=9999, max_str_len=20, nillable=False)

I just put work around for min_str_len, I do not find any attribute for min_str_len. Instead of work around is there any default way ?

Jahanzaib
  • 154
  • 1
  • 3

1 Answers1

0

You can subclass Integer type (or another one that fits best) and implement validate_native method.

Example for prime number check from docs:

from math import sqrt, floor

class Prime(UnsignedInteger):
    """Custom integer type that only accepts primes."""

    @staticmethod
    def validate_native(cls, value):
        return (
            UnsignedInteger.validate_native(value) and \
            all(a % i for i in xrange(2, floor(sqrt(a))))
        )

Source: http://spyne.io/docs/2.10/manual/05-02_validation.html#a-native-validation-example

Den Kasyanov
  • 870
  • 2
  • 11
  • 27