# Controlling the input

**URL:** <https://forum.djangoproject.com/t/controlling-the-input/28272>\
**Category:** Forms & APIs\
**Created:** [February 20, 2024, 6:56pm UTC](https://forum.djangoproject.com/t/controlling-the-input/28272 "2024-02-20T18:56:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [February 20, 2024, 6:56pm UTC](https://forum.djangoproject.com/t/controlling-the-input/28272/1 "2024-02-20T18:56:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 20, 2024, 7:06pm UTC](https://forum.djangoproject.com/t/controlling-the-input/28272/2 "2024-02-20T19:06:31Z")

</div>

> [@Gae58](#):
>
> 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](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#specifying_minimum_and_maximum_values)  
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.)

---

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [February 26, 2024, 9:35am UTC](https://forum.djangoproject.com/t/controlling-the-input/28272/3 "2024-02-26T09:35:28Z")

</div>

Thanks, I will try js
