regex - html5 pattern match float and/or percentage -


i'm working form validation , want use pattern attribute validate input field. field has following criteria:

  1. it must number (integer or float)
  2. can allow 2 decimal point (e.g.: 100.24)
  3. only 1 dot allowed (e.g.: 100.25.35 not valid)
  4. 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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -