Given the following document:
<input pattern="[a-z]"/>
Without filling in the input, running:
document.querySelector('input').checkValidity()
Returns true
.
Since an empty input would not match [a-z]
, why is HTML5 checkValidity() returning true
?
Use required
in order to not validate empty input.
<input pattern="[a-z]" required />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With