When I press the submit button for an empty HTML text input, this default message automatically appears. I want the border of the box to become red instead of this default message appearing. How do I do it?
Here’s the code for the box:
<div class="input-group" id="email-input">
<input type="text" id="email" name="email" autocomplete="off" required placeholder="Email">
</div>
2
Answers
You can use
novalidate
attribute for form, but it will be works the same way as non-required(your required will be ignored)We can do this by using JavaScript, there is a event called invalid that fires on every error. We will use that event and check by regex if text is proper email or not. We will create a function for this.
Here’s the code:
HTML
JavaScript
Note : This currently only supports validation of Email inputs.