Controlling the input

I need an explanation of a field of type Integer.
In models I specified this
fieldPeriod = models.IntegerField(validators=[MaxValueValidator(10), MinValueValidator(1)], blank=True, null=True)
The first query is how do I block the input before the 2-digit submit and have the field value not be greater than the value 10 ?
In forms I wrote this
'Period': forms.NumberInput(attrs={'maxlength': '2', 'class': 'form-control'}),
But it doesn’t work. What am I doing wrong

Nothing. You cannot prevent a user from entering a number outside that range. Even specifying the “max” and “min” attributes on the form doesn’t do that.

From the docs at <input type="number"> - HTML: HyperText Markup Language | MDN
for Specifying minimum and maximum values:

You can still manually enter a number outside these bounds, but it will be considered invalid.

Neither Django nor the browser controls that enough to prevent it.

(I guess you could probably write some JavaScript that would detect an invalid entry and change it before being submitted. I’m not sure how well that works out in practice though.)

Thanks, I will try js