-3

MinValueValidator

How can i define the min length of the IntegerField?

nummer = models.IntegerField(
        unique=True,
        validators=[MaxValueValidator(99999999),
                    MinValueValidator(00000001),
                    ])

Error Message:

SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Gilijar
  • 1
  • 1
  • 1
    Use `MinValueValidator(1)` – Willem Van Onsem May 30 '22 at 17:05
  • Thanks. I'm sorry my question was not specific enough. I want the Min of the numbers set to 8. If I use MinValueValidator(1) the user can set the number between 1 - 99999999. What I want is the numbers from 00000001 - 99999999. – Gilijar May 30 '22 at 17:09
  • 1
    that is the same: `00001` and `1` are the same. This is just a *formatting* issue, not a data issue. – Willem Van Onsem May 30 '22 at 17:09
  • 2
    Also see the [stringformat](https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#stringformat) template filter if you want to do that in templates – Abdul Aziz Barkat May 30 '22 at 17:16

1 Answers1

-1
nummer = models.IntegerField( unique=True, validators=[MaxValueValidator(99999999), MinValueValidator(1), ])

00000001 is wrong

M.J.GH.PY
  • 12
  • 2
  • It is already defined in the comment, by sir Willem Van Onsem. What this answer adds new? See how do I write a good answer [answer]. – Sunderam Dubey May 30 '22 at 17:14
  • 2
    A comment is not an answer. So this answer can't go down as "not an answer". A little explanation (as in the comments) would help though. – Gert Arnold May 30 '22 at 18:14