I have a rather straightforward question. I am currently utilizing Bootstrap 4.6
and am looking to implement form validation for my input field.
The requirement is to validate whether the input has a length of 5 characters or less, in which case it should display as "not fulfilled" in red. If the input is equal to or longer than 5 characters, it should display as fulfilled, indicated by green text.
Red: https://i.sstatic.net/Q99cs.png
Green: https://i.sstatic.net/u8AuI.png
I would like to use the Bootstrap 4.6 validation feature - you can find more information about this component here: https://getbootstrap.com/docs/4.6/components/forms/#validation
Thank you in advance for your assistance!
Below is the code snippet:
<form class="was-validated">
<div class="mb-3">
<label for="validationTextarea">Textarea</label>
<input class="form-control" id="validationTextarea" placeholder="Required example textarea" onkeyup="checkInput()" required></input>
</div>
</form>
function checkInput() {
var input = document.getElementById("validationTextarea").value;
if(input.length < 5) {
//display in red
} else if (input.length >= 5) {
//display in green
}
}