Using regex, I can check if it is decimal or not
^\d*\.?\d*$
But what I want to control is total length of those digit.
(^\d*\.?\d*$){1,10}
But I still cannot control it.
After 2 days later, my final solution is
(?=^\d*\.?\d*$)^.{1,10}$
Debuggex Demo
A DECIMAL(20,6) column has fourteen integer digits and six fractional digits. The integer digits require four bytes for nine of the digits and 3 bytes for the remaining five digits. The six fractional digits require 3 bytes. DECIMAL columns do not store a leading + character or - character or leading 0 digits.
For the number of decimal places stated, count that number of digits to the right of the decimal and underline it. The next number to its right is called the 'rounder decider'.
The decimal number with the greater digit in the tenths place is greater. For example, 9.85 is greater than 9.65. If the digits in the tenths place are equal, compare the digits in the hundredths place. The decimal number with the greater digit in the hundredths place is greater.
The greater a decimal is, the closer it is to one whole. The smaller a decimal is the farther it is from one whole. The first thing you need to look at is the digit number in each decimal. These each have two digits in them, so you can compare them right away.
Here's a solution:
^(?!.{10})\d*\.?\d*$
This will check the whole number isn't more than 10 characters.
If you want to check the whole number isn't more than 10 digits (not counting the dot), you may use
^((?!.{11})\d*\.\d*|(?!.{10})\d*)$
(^\d*\.?\d*$){1,10}
↑ ↑
The *
means, zero or more. So your regex means "zero or more times, from 1 to 10 times", so {1,10}
in this case is redundant. You need to remove *
or apply {1,10}
only to parts that doesn't have it.
For example, you can change your regex to:
^\d*(\.?\d{0,10})$
This matches numbers that has up to 10 digits after the dot. If you want to match a float number that has 10 digits in total, you can use negative lookahead (as @DenysSéguret already mentioned in his answer +1):
(?!.{10})\d*\.?\d*
It matches \d*\.?\d*$
only if it its length < 10 (including the dot).
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