Minlength attribute
The minlength attribute helps us to specify the minimum length of an input field in the form i.e. the minimum no. of characters that must be entered for the specific field. It can be useful to make the minimum length of a password that can’t be guessed or a telephone number in India as 10 digits so as to prevent any wrong input data submission.
Syntax:
<input type=" " id=" " name=" " minlength=" ">
Note: When the minlength attribute is set, an input field will not accept lesser characters than those specified.
Example: The implementation of minlength attribute
HTML
<!DOCTYPE html> < html > < head > < title >HTML minlength attribute</ title > < style > button { margin-top: 5px; } </ style > </ head > < body > < h1 >HTML minlength attribute</ h1 > < form > < label >Roll No.</ label > < input type = "text" minlength = "5" required /> < label >Email:</ label > < input type = "email" required /> < button >Submit</ button > </ form > </ body > </ html > |
Output:
How to perform form validation for a required field in HTML ?
The form data is very important for a website and the correct form data or valid form data must be submitted to the form. To make sure that the form data is valid or to make an input field mandatory, various attributes can be used. We shall discuss the following attributes in this article & will understand them with the help of examples.
Table of Content
- Required attribute
- Maxlength attribute
- Minlength attribute
- Min and max attribute
- Multiple attribute
- Pattern attribute