I have an input firstname
<input pattern="[a-zA-Z]" oninvalid="setCustomValidity('Please enter on alphabets only. ')" type="text" class="form-control" name="first_name" placeholder="Firstname">
I enter it as : qwerqwe
I kept getting
Please enter on alphabets only.
print out
Isn't qwerqwe
suppose to be valid ? I'm a little confuse now, and not sure what I missed here.
Can someone please provide me some hints on this ?
You are allowing only ONE character. You missed the +
sign:
<input pattern="[a-zA-Z]+" oninvalid="setCustomValidity('Please enter on alphabets only. ')" type="text" class="form-control" name="first_name" placeholder="Firstname">
As @le_m said in comments, you can write *
wildcard to allow empty input:
<input pattern="[a-zA-Z]*" oninvalid="setCustomValidity('Please enter on alphabets only. ')" type="text" class="form-control" name="first_name" placeholder="Firstname">
use title attribute for validation name.
pattern="[A-Za-z0-9].{1,}" title="Please Enter Valid Company Name"
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