Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære 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

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Awesome!

Completion rate improved to 5.56

bookSetting Length Constraints

Sveip for å vise menyen

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

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 3
some-alt