Reputation: 3898
I have text box as below
<input type="text" name="country_code" pattern="[A-Za-z0-9|]{1,50}" title="Three letter country code" required="true">
When I submit the form without entering any value in the text box, empty string "" gets submitted. I was hoping required="true" to catch it and throw an error. I think the combination of required and pattern attribute is causing it behave wrong.
Any thoughts
Upvotes: 2
Views: 224
Reputation: 1
just add "/" in end of required
<input type="text" name="country_code" pattern="[A-Za-z0-9|]{1,50}" title="Three letter country code" required />
Upvotes: 0
Reputation: 2394
Your syntax is wrong. Only required
is required.
<input type="text" name="country_code" pattern="[A-Za-z0-9|]{1,50}" title="Three letter country code" required>
It's actually required="required"
but you can ommit the second one and use the shorthand instead.
Upvotes: 2
Reputation: 48367
Please use required="required" insteed required="true"
<input type="text" name="country_code" pattern="[A-Za-z0-9|]{1,50}" title="Three letter country code" required="required">
Upvotes: 0