need to add error text by using js - If user type only 3 character in the field. How to do it? Thanks
<body>
<input type="text" class="user-input" minlength="4">
</body>
You can use the pattern attribute validation.
<input pattern=".{3,}" required title="3 characters minimum">
<input pattern=".{5,10}" required title="5 to 10 characters">
If you want to create the option to use the pattern for "empty, or minimum length" use like below
<input pattern=".{0}|.{5,10}" required title="Either 0 OR (5 to 10 chars)">
<input pattern=".{0}|.{8,}" required title="Either 0 OR (8 chars minimum)">
you could retrieve its value from the id:
let x = document.getElementsByClassName['user-input'].value;
if (x.length < 4) {
alert(`please enter at least ${x.length} characters`);
return false;
}