Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

605
Views
Regex for if a number contains a decimal point, it must have a decimal

There is another question, which deals with a mandatory decimal place, in this case, it is optional, and only if there are decimals. I need to check to see if a number is valid in a numeric input by comparing it to my regex on paste and keyed in. The number can contain up to 9 numbers, and if it has a decimal point, up to 6 decimal places.

For example:

123456789.123456

is a valid number, but

1234567890.1234567

or

1234567890.

is not valid. My regex thus far is:

/^(\d{0,9})(\.{0,1}\d{0,6})*$/

..but it still allows a decimal place without decimals.

RegExr link

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use

^\d{0,9}(?:\.\d{1,6})?$

See regex proof.

EXPLANATION

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  \d{0,9}                  digits (0-9) (between 0 and 9 times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (optional
                           (matching the most amount possible)):
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
    \d{1,6}                  digits (0-9) (between 1 and 6 times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )?                       end of grouping
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!