regex - html5 pattern match float and/or percentage -
i'm working form validation , want use pattern attribute validate input field. field has following criteria:
- it must number (integer or float)
- can allow 2 decimal point (e.g.: 100.24)
- only 1 dot allowed (e.g.: 100.25.35 not valid)
- may end percent(%) sign (but not necessary)
so should exact pattern regex
that. i'm trying following code how implement percent condition?
<input type="text" pattern="[0-9]+([\.][0-9]{0,2})?" title="this must number 2 decimal places and/or %">
you there. add %?
pattern:
input:invalid { color: red; }
<input type="text" pattern="[0-9]+(\.[0-9]{0,2})?%?" title="this must number 2 decimal places and/or %">
Comments
Post a Comment