- Атрибуты minlength и maxlength
- Кратко
- Как пишется
- Пример
- Как понять
- Атрибут maxlength
- Синтаксис
- Значения
- Значение по умолчанию
- Типы тегов
- HTML maxlength Attribute
- Definition and Usage
- Browser Support
- Syntax
- Attribute Values
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- HTML maxlength Attribute
- Applies to
- Examples
- Input Example
- Textarea Example
- Browser Support
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
Атрибуты minlength и maxlength
Атрибуты minlength и maxlength устанавливают полям ввода минимальное и максимальное количество символов.
Время чтения: меньше 5 мин
Это незавершённая статья. Вы можете помочь её закончить! Почитайте о том, как контрибьютить в Доку.
Кратко
Скопировать ссылку «Кратко» Скопировано
Атрибуты minlength и maxlength позволяют устанавливать минимальное и максимальное количество символов в полях ввода или .
Как пишется
Скопировать ссылку «Как пишется» Скопировано
input minlength="4" maxlength="8"> textarea minlength="50" maxlength="1000">
Пример
Скопировать ссылку "Пример" Скопировано
Создадим поле для ввода пароля и ограничим количество допустимых символов:
type="password" name="password" required minlength="8" maxlength="16">
label for="password">Введите пароль (от 8 до 16 символов):label> input type="password" id="password" name="password" required minlength="8" maxlength="16" >
Как понять
Скопировать ссылку "Как понять" Скопировано
Атрибуты minlength и maxlength устанавливают минимальное и максимальное количество символов в полях ввода или . Значением атрибутов должно быть целое число от 0 и выше. Если значение атрибутов не указано, или указано неправильно, ограничений по длине у поля не будет.
При добавлении полю обоих атрибутов, значение minlength всегда должно быть меньше значения maxlength . Если за этим не уследить, то поле всегда будет невалидным.
Атрибут maxlength
Устанавливает максимальное число символов, которое может быть введено пользователем в текстовом поле. Когда это количество достигается при наборе, дальнейший ввод становится невозможным.
Синтаксис
Значения
Любое целое положительное число.
Значение по умолчанию
Ввод символов не ограничен.
Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.
Типы тегов
HTML5
Блочные элементы
Строчные элементы
Универсальные элементы
Нестандартные теги
Осуждаемые теги
Видео
Документ
Звук
Изображения
Объекты
Скрипты
Списки
Ссылки
Таблицы
Текст
Форматирование
Формы
Фреймы
HTML maxlength Attribute
An element with a maximum length of 10 characters:
Definition and Usage
The maxlength attribute specifies the maximum number of characters allowed in the element.
Browser Support
The numbers in the table specify the first browser version that fully supports the attribute.
Attribute | |||||
---|---|---|---|---|---|
maxlength | Yes | Yes | Yes | Yes | Yes |
Syntax
Attribute Values
Value | Description |
---|---|
number | The maximum number of characters allowed in the element. Default value is 524288 |
❮ HTML tag
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
HTML maxlength Attribute
The maxlength attribute specifies the maximum number of characters allowed in the element.
Applies to
The maxlength attribute can be used on the following elements:
Examples
Input Example
An element with a maximum length of 10 characters:
Textarea Example
A text area with a maximum length of 50 characters:
Browser Support
The maxlength attribute has the following browser support for each element:
Element | |||||
---|---|---|---|---|---|
input | 1.0 | 2.0 | 1.0 | 1.0 | 1.0 |
textarea | Yes | 10.0 | 4.0 | Yes | 15.0 |
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.