@riccardofano
Posted
Hello Melad, excellent job on getting the javascript working!
I wanted to let you know there's an easier way to validate an email, in fact, the browser already does it for you.
Instead of checking if inputText
's value matches the regular expression you can just access inputText.validity.valid
thanks to having set <input type="email">
.
It does the exact same thing but it's a lot less work for you!
Having set input as type="email"
also allows you to style css elements by accessing its :valid
or :invalid
state so if you want to add a red border if your input is invalid you could do
.base-input:invalid {
border: 1px solid red;
}
You can take a look at my solution for more details. Hope this was helpful and have a wonderful day!
Marked as helpful
@melad99
Posted
@riccardofano thanks for your feedback and yes I tried type="email" but to be honest I just wanted to improve my skills with JavaScript so I chose the hard way but I will try the: valid and: invalid it's new to me and I appreciate sharing this with me ...thanks again ,good luck with your solutions.