Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Setting Length Constraints | HTML5 Built-in Validation
JavaScript Form Validation

bookSetting Length Constraints

When you want to control how many characters a user can enter in a text field, you can use the HTML5 minlength and maxlength attributes. These attributes allow you to set the minimum and maximum number of characters that are accepted for an input. This is especially useful for fields like usernames, passwords, or comments, where you want to prevent entries that are too short or too long.

index.html

index.html

copy

When you use minlength and maxlength on an input, browsers automatically check the length of the user's entry when the form is submitted. If the input is shorter than the minlength or longer than the maxlength, the browser will prevent the form from being submitted and will usually show a built-in error message. This makes it easy to enforce basic length rules without writing any JavaScript.

question mark

Which attribute enforces a minimum length on a password field?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you show me an example of how to use minlength and maxlength in an HTML input?

Are there any limitations or browser compatibility issues with these attributes?

How can I customize the error messages shown to users?

Awesome!

Completion rate improved to 5.56

bookSetting Length Constraints

Deslize para mostrar o menu

When you want to control how many characters a user can enter in a text field, you can use the HTML5 minlength and maxlength attributes. These attributes allow you to set the minimum and maximum number of characters that are accepted for an input. This is especially useful for fields like usernames, passwords, or comments, where you want to prevent entries that are too short or too long.

index.html

index.html

copy

When you use minlength and maxlength on an input, browsers automatically check the length of the user's entry when the form is submitted. If the input is shorter than the minlength or longer than the maxlength, the browser will prevent the form from being submitted and will usually show a built-in error message. This makes it easy to enforce basic length rules without writing any JavaScript.

question mark

Which attribute enforces a minimum length on a password field?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 3
some-alt