I am creating a form and it has some fields that are compulsory to fill like name and email. I am using the HTML required attribute to enforce that.
<input id="name" type="text" pattern="[a-zA-Z]+" required="required" />
The thing is I am also providing pattern attribute to ensure that I get the correct input. For its styling I am using the following code
input.invalid {
border-color:red;
}
input, input.valid {
border-color: green;
}
But since I am also using the required attribute, it makes the borders red when the form is loaded as the fields are empty at that time. Is there a work around for this or do I have to be just stuck with this?
Any help is appreciated, thanks.
:requiredto style the input withrequiredattribute