javascript - RegEx- Validate negative and positive decimal numbers -


i trying build regex allow both negative , positive decimal numbers following rules.

  1. there can not more 2 digits after decimal point
  2. decimal point optional
  3. total length including decimal point should not exceed 12 char
  4. if no decimal point there, max length should not exceed 9 char

can me out? lot in advance.

check regex.

^[+-]?[0-9]{1,9}(?:\.[0-9]{1,2})?$ 

this regex says

  • sign optional
  • at least 1 , max 9 digits integer part
  • if decimal point there, @ least 1 , max 2 digits after it.

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -