I'm working with form validation and want to use pattern attribute for validate the input field. The field has the following criteria:
So what should be the exact pattern RegEx
for that. I'm trying with the following code but how to implement the percent condition?
<input type="text"
pattern="[0-9]+([\.][0-9]{0,2})?"
title="This must be a number with up to 2 decimal places and/or %">
You are almost there. Add %?
to your pattern:
input:invalid {
color: red;
}
<input type="text"
pattern="[0-9]+(\.[0-9]{1,2})?%?"
title="This must be a number with up to 2 decimal places and/or %">
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